Finding best performance with benchmarking tool

Me and my friend are doing several puzzles and contests here and he is doing everything with C#, while I’m doing everything with JavaScript. Since we try to solve almost everything with learning and genetic algorithms it comes to the point where performance matters.

Thats why I want us JavaScript addicts to get the best performance out of our code… To have a chance against C# etc.

So I start with a few benchmarks:

comparison of loops:

if vs. switch vs. mapper:

lookup: array vs, object:

pop vs slice:

match vs. regex vs. indexOf:

copy/clone array:

Help to improve this thread, and give JS some speed! Post your benchmarks!


This tool is indeed a nice tool to benchmark JS.
Calculate 2D Distances:

But optimization is a tricky thing.
What I read and learnt the hard way is that you shouldn’t optimize only small parts.
Premature optimization is the root of all evil
To get the best performance, find the bottlenecks of your whole genetic algorithm.
Sometimes it’s the creation of new objects, or the garbage collector, or builtin functions like sqrt().
I spent days tweaking some minimal functions in C# to optimize them to the max, just to find out that 95% of the CPU time was being used in object creations…

C# has the advantage of having a good profiler and debugger (the ones inside Visual Studio Community).
I don’t know if JS has those kind of tools.

1 Like

Thats absolutely true! This tool can’t figure out how to structure your code efficiently :slight_smile:

As a caution, these numbers are significantly less reliable (for use in CG) if run in a non-mozilla-based browser. CG uses SpiderMonkey to run JS code, so running benchmarks in Chrome (V8-based) or other browser is not necessarily applicable.

  • danBhentschel