Short answer: NO
IL2CPP is tightly connected to the Unity environment and it's not possible to use it outside of Unity. You would need to write your own converter(?) to do such a thing.
Longer answer
IL2CPP doesn't do any magic in terms of performance improvement. Comparing C++ with C# with IL2CPP code should give (almost - more below) no performance benefit.
IL2CPP is performant compared to C# code written for Unity specifically for few reasons that have nothing to do with C++.
Why Unity is unique and needs IL2CPP:
- Unity API is very heavily reliant on main thread performance, as the whole Unity API was written almost 10 years ago, where 2 Core CPUs were top-notch and everyone believed that we will have 20-50GHz single-core CPUs by now.
- Unity makes a lot of assumptions that you will use their API for everything, begging from IO to Threading and GPU access, which is heavily bound to C++ core.
- Unity needs to be wrapped with Unity objects (MonoBehaviours and GameObjects) to be used for almost anything, you cannot write your own native anything. (This is a simplification)
- Unity is written in C++, so it needs to do something very similar to Marshalling, and it's not very efficient.
So why IL2CPP?
- Unity cannot convert its already very legacy backend (Mono) and its legacy API to be multithreaded since Mono have a lot of assumptions about your code that are not easily convertible to "simple" unity API.
- Unity core is written in C++, so they are eliminating any form of Marshalling all together by skipping Mono "translator".
- IL2CPP converts highly inefficient C#, single-threaded code to multithreaded C++, where possible, and it does this by analyzing IL code.
Is it worth converting other C# to C++?
No! Compare any arbitrary, optimized C# code that was precompiled by AOT to (modern) C++. You should get the same performance! Identical I would say.
C# is compiled to IL (Intermediate Language) which as the name suggests is Intermediate. It's converted in runtime to Native Binary code (only when needed), that is what C++ is compiled into. You can force this conversion by skipping IL generation by running Ahead of Time compilation (AOT).
The ONLY thing that your C# code will be less performant is when you are abusing GC's ability to clean up after you.