▲ | hatthew 4 hours ago | |||||||||||||||||||||||||
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? | ||||||||||||||||||||||||||
▲ | Dylan16807 3 hours ago | parent [-] | |||||||||||||||||||||||||
Do you think a slightly more complex piece of math that can't be replaced with an equation would have significantly different performance from the benchmark? I don't. So the simple math just makes things easier, it doesn't harm results. Your suggestion to skip the math entirely is the apple-smash. > Since nobody does large loops in python Oh I doubt that. Numpy would be fine as a different entry. | ||||||||||||||||||||||||||
|