Same program faster on Linux than Windows — why?

前端 未结 3 1979
臣服心动
臣服心动 2020-12-19 07:27

The solution to this was found in the question Executable runs faster on Wine than Windows -- why? Glibc\'s floor() is probably implemented in

相关标签:
3条回答
  • 2020-12-19 08:06

    Apparently the difference is system related.

    You might use strace to understand what system calls are done, eg

    strace -o /tmp/yourprog.tr yourprog
    

    and then look into /tmp/yourprog.tr

    (If an equivalent of strace existed on Windows, try to use it)

    Perhaps your program is allocating memory (using mmap system call), and perhaps the memory related system calls are faster on Linux (or even on Wine) than on Windows? Or some other syscalls give faster functionality on Linux that on Windows.

    NB. I know nothing about Windows, since I'm using Unix systems since 1986 and Linux since 1993.

    0 讨论(0)
  • 2020-12-19 08:16

    You'd be surprised what system libraries are involved. Just do ldd on your app, and see which are used (ok, not that much, but certainly glibc).

    In order to completely trust your findings about execution speed, you would need to run your app a couple of times sequentially and take the mean execution time. It might be that the OS loader is just slower (although 4s is a long loading time).

    Other very possible reasons are:

    1. Different malloc implementation
    2. Exception handling, if used to the extreme might cause slowdown (Windows GCC, MinGW, might not be the optimal exception handling star of the show)
    3. OS-dependent initialization: stuff that needs to be done at program startup on Windows, but not on Linux.

    Most of these are easily benchmarkable ;-)


    An update to your update: the only thing you can now do is profile. Stop guessing, and let a profiler tell you where time is being spent. Use gprof and the Visual Studio built-in profiler and compare time spent in different functions.

    0 讨论(0)
  • 2020-12-19 08:17

    Do benchmarking in code. Also try to compile with visual studio. On windows if you have some application like Yahoo Messenger, that are installing hooks, they can very easy slow down your application loading times.

    On windows you have: QueryPerformanceCounter On Linux: clock_gettime

    0 讨论(0)
提交回复
热议问题