+ 1

Does binary file runs faster?

For eg: I converted my python code into a binary file(exe/out), Does it run faster now?

11th Oct 2019, 2:24 PM
Sarthak
Sarthak - avatar
8 ответов
+ 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.
11th Oct 2019, 3:13 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 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.
11th Oct 2019, 3:31 PM
Taste
Taste - avatar
+ 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?
12th Oct 2019, 2:48 AM
Sarthak
Sarthak - avatar
+ 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.
12th Oct 2019, 8:18 AM
Taste
Taste - avatar
+ 2
Aaron Eberhardt So, there's no advantage of learning python if we are making a better performance application?
12th Oct 2019, 8:10 AM
Sarthak
Sarthak - avatar
+ 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.
11th Oct 2019, 2:36 PM
★«D.Connect_Zone»
★«D.Connect_Zone» - avatar
+ 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
12th Oct 2019, 3:53 AM
Taste
Taste - avatar
+ 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).
12th Oct 2019, 7:35 AM
Aaron Eberhardt
Aaron Eberhardt - avatar