Hacker News new | ask | show | jobs
by opticfluorine 271 days ago
I have occasionally, just for fun, written benchmarks for some algorithm in C++ and an equivalent C# implementation, them tried to bring the managed performance in line with native using the methods you mention and others. I'm always surprised by how often I can match the performance of the unmanaged code (even when I'm trying to optimize my C++ to the limit) while still ending up with readable and maintainable C#.
3 comments

JIT compilers can outperform statically compiled code by analysing at run time exactly what branches are taken and then optimising based on that.
Does this include the GC at the end of it all? Because if that happens after the end timestamp it's not an exact comparison. I read something once about speeding up a C/C++ compiler by simply turning free into a no-op. Such a compiler basically allocates more and more data and only frees it all at the end of execution, so then doing all the free calls is just wasted CPU cycles.
Could you please share some benchmark code? It would be incredibly useful as a learning aid!