The running time of python program is very short in ubuntu compared to windows. What for?

I implemented the Dijkstra algorithm in Python and ran the script under Ubuntu and Windows 8. Both x64 architectures.

I have profiled the script with python -m cProfile name.py

I was surprised to see that the program took half the time in Ubuntu compared to Windows.

Ubuntu runtime for 1000 x 1000 matrix: 0.4 sec

Windows Runtime for 1000 x 1000 matrix = 1.2 sec

They are the same double loading machine.

How does this happen?

+3


source to share


2 answers


First, it is obvious that although the python versions may be the same, they were compiled with different compilers, and naturally this means that the optimization levels are completely different. You could recompile python for both systems using gcc for example and run the whole thing again. However, I advise you to do this only if you are sure of what you are doing. More specifically for linux, as many of the processes that run are highly python dependent. Take a look at this discussion.

Second, windows naturally take up much more resources than Linux, and many more processes are launched from window windows, and each process, as a rule, is an endless loop that takes up resources.



OS based performance comparison is a misconception. It's basically like comparing apples to oranges. Each system has different ways of managing memory and running processes. The file system is another very important part - since python is an interpreted language in most cases, each import performs disk operations.

0


source


In fact, there are several things that were causing Python to be slow on my machine. However, I have no statistics with me, so no evidence on my part. You may need to check them out as well (with a pinch of salt, -)).

  • Antivirus - If antivirus is available, add the Python location as well as the program location to the whitelist and then try running them; this actually gave me nearly 33% performance.
  • Process priority is a high priority process while running (in my case it was a long process, so I just do it through the task manager)
  • The Right Drivers - Trust me. While it sounds silly, updating device drivers improves performance. The thing is, when I run the python process from the external hard drive, it has improved slightly over the internal hard drive. Once I updated my hard drive driver, it actually started to perform better than my external hard drive (it should be noted that it is still slower than the Linux version).


However, they may not help you achieve performance like Linux. The main reason is that both python can be compiled by different c compilers. Libc might work as well.

0


source







All Articles