Micro benchmarks are meaningless trying to compare C and Python or Java for the suitability for back end web apps. All need to do the same string handling (processing requests), database/data transformation calls, and string/template processing. Doing that work in C, with safety checks and error handling, you're not going to get the same relative performance as you would on some microbenchmark.
I'm not saying Python is going to beat C in raw performance but that C, when used to write a web app doing normal web app things, is not going to be hundreds of times faster than Python. It's definitely not going to be a hundred times faster than Java. However in both of those languages you get really useful features you'd either need to write yourself or use a library that's little to no faster than those languages' runtimes.
Doing that work in C, with safety checks and error handling, you're not going to get the same relative performance as you would on some microbenchmark.
As a user of C++, Java and Python, I assure you that the difference is measurable, and the ballpark for "business logic" is indeed:
Python ~100x slower than C.
Java ~2x slower than C.
Java suffers most from the absence of value types, preventing zero-overhead abstraction over simple numeric types, which leads to an order magnitude more memory allocations and a lot of pointer chasing. Python, as mentioned, is interpreted so that even i = 1; i + i involves dictionary lookups and "virtual" dispatches rather than a single assembly instruction.
It's definitely not going to be a hundred times faster than Java.
I may not have been clear, the 100x was comparing Python to Java, not C to Java.
Which is exactly why I was saying that you don't need to go to C to get good performance (and a dearth of safety and libraries), you can easily use Java and Go and already get 2 order of magnitude of improvement.
Which is exactly why I was saying that you don't need to go to C to get good performance (and a dearth of safety and libraries), you can easily use Java and Go and already get 2 order of magnitude of improvement.
Thanks for clarifying for me as that makes way more sense. I've switched from Python to Java several times for performance improvements. Python was great for a prototype but once scaling was needed I switched to Java before trying to scale out the hardware.
In the general case I think that is overkill and most apps spend so much more time waiting on things like database connections or talking to remote API that interpreted languages aren't really wasting a ton of time in the interpreter. So I don't necessarily agree that some huge amount of resources is "wasted" with the popularity of interpreted languages in the back end of web apps. At the same time I'm often horrified when I see someone throw more hardware at performance problems when it's wasteful code/practices causing the problem.
1
u/giantsparklerobot Nov 26 '18
Micro benchmarks are meaningless trying to compare C and Python or Java for the suitability for back end web apps. All need to do the same string handling (processing requests), database/data transformation calls, and string/template processing. Doing that work in C, with safety checks and error handling, you're not going to get the same relative performance as you would on some microbenchmark.
I'm not saying Python is going to beat C in raw performance but that C, when used to write a web app doing normal web app things, is not going to be hundreds of times faster than Python. It's definitely not going to be a hundred times faster than Java. However in both of those languages you get really useful features you'd either need to write yourself or use a library that's little to no faster than those languages' runtimes.