Executable runs faster on Wine than Windows -- why? Executable runs faster on Wine than Windows -- why? linux linux

Executable runs faster on Wine than Windows -- why?


edit: It turned out that the culprit was floor() and not rand() as I suspected - see the update at the top of the OP's question.

The run time of your program is dominated by the calls to rand().

I therefore think that rand() is the culprit. I suspect that the underlying function is provided by the WINE/Windows runtime, and the two implementations have different performance characteristics.

The easiest way to test this hypothesis would be to simply call rand() in a loop, and time the same executable in both environments.

edit I've had a look at the WINE source code, and here is its implementation of rand():

/********************************************************************* *              rand (MSVCRT.@) */int CDECL MSVCRT_rand(void){    thread_data_t *data = msvcrt_get_thread_data();    /* this is the algorithm used by MSVC, according to     * http://en.wikipedia.org/wiki/List_of_pseudorandom_number_generators */    data->random_seed = data->random_seed * 214013 + 2531011;    return (data->random_seed >> 16) & MSVCRT_RAND_MAX;}

I don't have access to Microsoft's source code to compare, but it wouldn't surprise me if the difference in performance was in the getting of thread-local data rather than in the RNG itself.


Wikipedia says:

Wine is a compatibility layer not an emulator. It duplicates functions of a Windows computer by providing alternative implementations of the DLLs that Windows programs call,[citation needed] and a process to substitute for the Windows NT kernel. This method of duplication differs from other methods that might also be considered emulation, where Windows programs run in a virtual machine.[2] Wine is predominantly written using black-box testing reverse-engineering, to avoid copyright issues.

This implies that the developers of wine could replace an api call with anything at all to as long as the end result was the same as you would get with a native windows call. And I suppose they weren't constrained by needing to make it compatible with the rest of Windows.


From what I can tell, the C standard libraries used WILL be different in the two different scenarios. This affects the rand() call as well as floor().

From the mingw site... MinGW compilers provide access to the functionality of the Microsoft C runtime and some language-specific runtimes. Running under XP, this will use the Microsoft libraries. Seems straightforward.

However, the model under wine is much more complex. According to this diagram, the operating system's libc comes into play. This could be the difference between the two.