![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#11
| |||
| |||
|
|
This kind of benchmarh is meaningless.. The reason for the huge difference is that the C++ compiler hoists the loop, as it sees no sensible reason to call an empty function 50000 times, the C# compiler does not do this, it simply calls the function which only contains a ret. Inlining and optimizing away a call to an empty function is well within the capabilities of the CLR JIT. |
#12
| |||
| |||
|
|
"Jon Skeet [C# MVP]" <skeet (AT) pobox (DOT) com> wrote in message news:MPG.2091f2b49096c93598daf1 (AT) msnews (DOT) microsoft.com... Ben Voigt <rbv (AT) nospam (DOT) nospam> wrote: This kind of benchmarh is meaningless.. The reason for the huge difference is that the C++ compiler hoists the loop, as it sees no sensible reason to call an empty function 50000 times, the C# compiler does not do this, it simply calls the function which only contains a ret. Inlining and optimizing away a call to an empty function is well within the capabilities of the CLR JIT. That was my thought too. I suspect it'll still perform the loop iteration, however, whereas the C++ compiler may well have removed that loop completely, which still means it's not a good benchmark. Oh, and if it's desired not to have the loop optimized away, touch a volatile variable from inside the function. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |