
Ask HN: Fastest language for iteration and arrays manipulation? - Fr33maan
I currently have a microservice written in js which basically query a redis db and iterate few hundred or thousands times while geting&#x2F;pushing values from&#x2F;to arrays in multiple for loops.<p>It&#x27;s made to build line of sight of players for a mmo game.<p>The service run as a loop, ideally at 60FPS (1 iteration = 16ms). More players in the world = more time to iterate.<p>I have the belief that writing in C++ the same would be faster but: 
1. That&#x27;s a belief, I didn&#x27;t do any benchmark
2. I don&#x27;t have the belief that C++ will be the fastest to do it.<p>What HN does think about that ?
======
al2o3cr

        query a redis db
    

General rule: if you're looking for "fastest", pulling data over the network
is not part of the solution.

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.

~~~
Fr33maan
Basically the network query is done before the computing tasks, the network
remark is very true. I don't know cpp, only java php and js but I know I need
to learn a new one for this task, I'm just wondering which one.

------
tjchear
It doesn't have to be fastest, it just has to be faster than what you're using
now. C++ compiler has a suite of automatic compiler optimizations that'll make
your code performant. Things like loop unrolling, strength reduction,
vectorization, cache optimization can make your code many times faster than
what you can muster with js.

There's a reason why many AAA titles use C++. No benchmark necessary.

~~~
Fr33maan
Why I wouldn't need the fastest and only take a faster solution? You are
answering to the question of C++ usage but do you know other languages that
could do it faster? I know that c++ has dozens of years of optimizations and
it is considered as a very powerful and fast language. Is it the best choice I
can make? What about c, rust, java, etc...? Will they be slower that cpp?

~~~
tjchear
Because language choice is more than just about whether it's the fastest for
your specific concern at the moment; it may be slow or non-ideal in other
situations. C++ in general is pretty fast. I may be biased since I used to
write C/C++ optimizations for a living.

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.

~~~
Fr33maan
Thanks for the answer, I understand better your point. What I understand from
your messages is that C++ should be a good solution.

------
unlinked_dll
You should probably identify and quantify the bottlenecks first. My guess is
this in an XY problem and you’re IO bound or your architecture is doing
something bad like a linear complexity algo calling a linear complexity algo
in your iteration, and a 1:1 translation to C++ probably won’t have much
benefit.

~~~
Fr33maan
Actually the IO happen outside of the loops I'm trying to optimize, I
shouldn't have mentioned it as they are not part of the problem.

------
abjKT26nO8
Maybe Fortran?

~~~
Fr33maan
I was thinking about perfored cards too

