DEV Community

Discussion on: Features of C :)

Collapse
 
sh4zkh4n profile image
Sh4zKh4n

Hey, it's because python is written in C, so when you have code in C, your going from C to machine code and it's compiled at the beginning. Python is written in C, so your going from python to c and there's something about the compilation which isn't at the beginning but dynamic. Which means with c you going back and forth in 2 levels and in python 4 levels. All of which will add on time. With say a for loop day it's going to increase the steps by *2 but because of the added time of compilation and wait compile down one level, the speed decrease is significantly more.

Collapse
 
faranaiki profile image
Muhammad Faran Aiki

No, "C to machine code" is just plain wrong. C is not interpreted. C is compiled, meaning there is no "go back and forth". If you write a programming language, let us say a compiled one, using C or using other language, and with an addition rule that the compiler can optimizes it, then the speed would be the same as C. Take a look at Rust, the language itself is using OCaml (at first, which is made using C).
Nowadays, C is compiled first to Assembly. There are some compilers that translate, assembling, C directly to machine code, TCC for example.
Python does not go to C. Who compiles Python code into C in terms of normal Python? Python use the opcode itself to optimizes itself. Take a look at the "dis" module in Python.

Thread Thread
 
sh4zkh4n profile image
Sh4zKh4n

Sorry your right if your going one way. I was thinking of the classic nested for loop.

For i in xxx
For b in xxx

Should have added that in. In my head that was the classic example. Back and forth.