I’m trying to create a processing-intensive application within Unity. So, I decided to implement the most intensive operations in faster compiled languages. For this purpose, I decided to conduct a simple test: three implementations of a function that calculates n prime numbers, one native in C# within Unity, another in Rust, and another in C, and to measure their performance for a million numbers and time them using Stopwatch.
I wanted to know if the performance of Rust or C/C++ would be marginally better or much better. So I wrote the implementations in quite similar way, compiled the DLLs, imported them as plugins and, well… I got quite a surprise:
CountPrimesC :: Calculated 1000000 primes in 2312 ms
CountPrimesRust :: Calculated 1000000 primes in 3731 ms
CountPrimesUnity :: Calculated 1000000 primes in 2273 ms
Now I’m trying to understand why the performance of these languages, usable for writing the kernel of an operating system, is so poor.
Any ideas?
1