DEV Community

loading...

Discussion on: Features of C :)

Collapse
faranaiki profile image
Muhammad Faran Aiki

"Speed c is fast yeah it is because of less inbuilt functions as i have texted above it have inbuilt functions which makes it a rich library languages but you can simply say that they are quite less then other High level language," actually, built-in function can has nothing to do with the performance. What makes C fast because it is (the compiled code) interpreted with the CPU/processor itself, whereas Python or Java is interpreted by a software, and that software is interpreted by CPU/processor.

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.