Ask HN: Fastest language for iteration and arrays manipulation?
I currently have a microservice written in js which basically query a redis db and iterate few hundred or thousands times while geting/pushing values from/to arrays in multiple for loops.
It's made to build line of sight of players for a mmo game.
The service run as a loop, ideally at 60FPS (1 iteration = 16ms). More players in the world = more time to iterate.
I have the belief that writing in C++ the same would be faster but: 1. That's a belief, I didn't do any benchmark 2. I don't have the belief that C++ will be the fastest to do it.
What HN does think about that ?
12 comments
[ 2.6 ms ] story [ 40.4 ms ] threadThere's a reason why many AAA titles use C++. No benchmark necessary.
I can't speak for other languages; languages with JIT optimizations could in theory be faster than fully optimized C++ code, since it could take advantage of run-time information, such as hot paths and hot fields.
If you care about the fastest performance possible, you're asking the wrong question. I'd benchmark different languages for the specific code I want.
Nobody needs “fastest”. “Fast enough” always is sufficient.
Also, I don’t think anybody has the money to pay for ‘fastest’ for any significant algorithm. CPUs are just too complex to be able to categorically claim “this is the fastest possible”.
There likely also is a point where you aren’t willing to pay for ‘yet a bit faster’. You may want to pay $1,000,000 to double your speed, and $10,000,000 to do that again, but at some moment, the price for a 1% speed increase will be too high for you, and that isn’t even the end game, which is “give us loads of money and we’ll see what we can do to get any speed increase”.
As for the choice of language, it's going to be heavily motivated by what languages you (or your team) know how to benchmark and optimize. It doesn't matter if, say, Befunge is the "fastest" if you don't have anybody working on it that can optimize it.