Swift is an interpreted language. Can it be so fast, or 210 times faster than the speed of some special functions? Should the four arithmetic operations not be improved so much? Swift is an interpreted language. Can it be so fast, or 210 times faster than the speed of some special functions? Should the four arithmetic operations not be improved so much?
Reply: opposite to the questioner's intuition, the four arithmetic operations are exactly the slowest part of Python (relative to C. An integer a + B goes through hundreds of lines of C code in the Python VM, including bytecode explanation, indirect calls from dynamic types, and seamless support for bigint. To perform the four operations faster than Python, you only need to increase the performance by an order of magnitude than C. This is also the reason why JIT prefers to use four arithmetic operations for demonstration.
In actual UI code, the performance of the language used by the user logic is irrelevant. Because most of the user logic is nothing more than "changing the status of the UI element BCD when user operation A occurs", "extracting the field XYZ from the server returned results and setting it to the corresponding UI element", etc, glue code. On average, a few hundred lines of framework code are required to execute each line of user code. You only need to know step into framework code in the debugger. Therefore, as long as the framework is implemented in an efficient language, it does not matter if the user code is a hundred times slower than Python. Benchmark:
1. Actual test cases
2. Specific implementation of various languages
You can use Swift to compile and run the machine code as you like, so it should not be compared with Python running on the official interpreter.
Python can also be compiled, and LLVM is also used. Comparison between Swift and such Python makes sense.
The package name is Numba. You can add a line of decorator above the function to compile the JIT function into a machine code during running.
For the four arithmetic operations that the subject cares about, for example, the Python with Numba is faster than C.
What's strange about this ?! In mainstream programming systems, it is always difficult to find a language that is slower than CPython. Do you mean to compare it with a scripting language? Wash and sleep, of course, the specific running points in a specific environment. Pypy is faster than cpython to run the Fibonacci series. How many online applications are there? Don't worry about it.
This time, I really despise the machine code compiled by swift. python (which should be CPython) compiles the bytecode that is run by the python virtual machine.
In most cases, there must be a huge difference in operating efficiency. However, I think the 210-fold value is the conclusion in a specific scenario that is particularly swift.
In fact, the comparability between swift and python is not that big. It is possible to compare it with golang. We recommend that you understand LLVM first and compile it into an intermediate expression, however, it is further compiled into pure machine code. Essentially, it is no different from that compiled by C and ObjC. It is a compilation of machine code, so the efficiency problem can be forgotten.
When you need to generate results in real time, just like an interpreted script language, you can compile the result twice and change the output machine code to the intermediate output and express it to the interpreter. LLVM is a revolutionary concept in English, which means "RC4 encryption". It is a cryptographic pseudo-random number generation algorithm with the main performance overhead. It is actually a four-digit operation.
It can be seen how bad the four operations of Python are.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.