+ 1
Does binary file runs faster?
For eg: I converted my python code into a binary file(exe/out), Does it run faster now?
8 Réponses
+ 5
Obviously binaries are faster than human readable text. Python however usually doesn't create binaries. And if it does it seems to be some hacky thing where the code is put into C arrays to make it load a bit faster. That's not what I'd call a (standalone) executable binary file.
Real binaries can only be produced by languages that compile to machine code like C, C++ and Rust. That's the reason why you can use them everywhere, whereas Python only works on platforms that support a Python interpreter. Also these binaries are usually about 100 times faster when compared to Python code.
+ 4
your tags include py2exe, if that what you're using for converting then no.
py2exe bundle your script and other library you're using, along with their interpeter (you can see python??.dll here http://www.py2exe.org/index.cgi/FAQ ).
so when the exe run, your script will just get executed by that interpreter.
perfomance wise, its not much different.
but its good for distribution. then again, from common windows user standpoint a program wont complete without .exe
also not needing to install python is a huge plus.
the only downside is filesize. without converting it would only take few or less than a megabytes. but its 2019 no one care about a few megabytes difference.
+ 3
But guys, Isn't Interpreter a subset of Compiler?
Can't we transform interpretable python code into a true binary? After all, the result shown is interpreted by python interpreter each line into a machine code and shown to user.
Is there any software, that truly converts python code into a binary?
Or maybe there's a software that can convert python code into c++ code and so, c++ code is compiled into binary?
+ 3
i think what python do the best is in development stage, because of the way python script is written, its shorter and readable thus make development more efficient.
but if you're really into performance, python cant beat compiled language.
+ 2
Aaron Eberhardt
So, there's no advantage of learning python if we are making a better performance application?
+ 1
Binary is machine language. So i think it will run faster.
A bit got confused with question tho.
Gonna see other answer here too.
+ 1
you can compile it to bytecode if i remember correctly, like .java to .class but its .py to .pyc
its slightly faster on load time, i cant remember which command. you can look for it somewhere
+ 1
Sarthak 🇳🇵 Python can never be compiled to machine code because of it's design. Python is too modular so it needs to interpret the source code at runtime to operate correctly. That's why you write less code in Python but that's also the reason why Python is such an incredibly slow language (although it has already been optimized for speed).