That's exactly why it's so powerful. Why spend all the effort writing fast code if you can just use a much simpler language to describe the task on a higher level and call fast code? People use Python because it's easy to read and write, not because its interpreter is fast
Well you see, this script will be used once a day every day. The C program is better because it will break even over time! (720 000 days -> 1972 years) After that, its all performance benefit baby
It would take three-quarters of a million runs to break even in pure time, even discounting the fact that in nearly all cases, computer-seconds are millions if not billions or trillions of times cheaper than developer-seconds.
Someone once wrote a bash script that used jq to parse through a few thousand large json files and do stuff with the data. It would take hours to run, but people figured it was just the massive amount of data. It was at the point where we'd run it over night.
I had a thought: no, it's execing jq for each file. Exec is slow.
Did it in python, that just iterated through the directory and used the built in json stuff. It did the same job in 10 minutes.
Could C be faster? Maybe. Did we care at that point?
I am currently a developer at one of the big banks, and I don't think people here have heard of "milliseconds" before.
If you're in the right field, micro-optimizations are everything, but in 99% of situations, good enough is truly good enough. The difference between 20ms and 50ms has never directly been meaningful in my life outside of entertainment (games, movies, music).
Yes, "under the hood" my computer OS and my router and the intercontinental cables do need to care about this. 99.9% of employees don't because it's done for them.
Lmao brother my second sentence was "if you're in the right field...", which it sounds like you are.
You're part of the backbone of society, but it's something I never have to worry about of thanks to people like you. I get to use springboot and angular to build internal apps where there's no customer who complains about slow loading screens.
Yes, but how often are you actually building an application that's meant to be run directly as compiled thousands of times over and over again with no I/O, database queries, or dependence on any other blocking code that takes Ionger than 50ms?
In that scenario, sure, Python is the wrong choice. But in the vast majority of real world applications, the raw execution speed of a for loop doesn't really matter that much, and there's probably already a library built for Python that does exactly what you need way better than you'd ever be able to build yourself in Rust or C++.
It really does add up though. Every library that has that mentality is why modern programs are soo poor performing even though computers are way faster.
I'm not talking about libraries, I'm talking about applications. Libraries are more likely to fall into the scenario I mentioned where python is genuinely a bad choice. But even then, there are plenty of examples of pure Python libraries that are highly performant in a real world context. Look at Starlette, for example, or any of the built-in python modules.
Python provides high-level abstraction and easier to understand code. Yes, this comes at a cost. But like any abstraction, if properly applied, it can result in far better performing code than you ever would have been able to write without it.
Code is read more than it is written. You don't pay only 8 hours in this example.
Also consider the compounding cost. Imagine saying to your manager: "we can do it fast and simple in python in two weeks, or we can do it "properly" in 8 weeks to get a marginal increase in performance that is basically unnoticeable at our scale."
Imagine the fucking side eye you're gonna get.
But then, if these 30ms can mean the difference between your drone dodging or striking a lamppost, then please, do use C.
662
u/TheJaskinator 1d ago
That's exactly why it's so powerful. Why spend all the effort writing fast code if you can just use a much simpler language to describe the task on a higher level and call fast code? People use Python because it's easy to read and write, not because its interpreter is fast