▲ | Dylan16807 5 hours ago | ||||||||||||||||||||||||||||||||||
I do not accept your analogy. This program is a perfectly reasonable "bite". It's not doing weird stuff. | |||||||||||||||||||||||||||||||||||
▲ | hatthew 3 hours ago | parent [-] | ||||||||||||||||||||||||||||||||||
The program is a useless toy that nobody would write and expect to be performant in real life. I can write an optimized version of the algorithm that prints the exact same output (barring edge cases) without looping. With this new algorithm (really just a single expression), the C program is 500x faster than before and the python script is 5000x faster than before. So python is only 10x slower than C in this example (and I'd imagine that this is measuring more overhead and less arithmetic). Presumably the C compiler has a relative advantage at optimizing the looped algorithm vs the arithmetic algorithm. How much? Is C 100x faster than python, or was the compiler able to get closer to the non-looping algorithm than python? How close? Is it something about the arithmetic or the looping that's natively faster in C? What part of it was optimized by the compiler? Since nobody does large loops in python, would python be more comparable if we introduced a C-backed library like numpy? What other objects do you think we should bash this apple with? | |||||||||||||||||||||||||||||||||||
|