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: http://jsben.ch/#/BQhED
if vs. switch vs. mapper: http://jsben.ch/#/o0UDx
lookup: array vs, object: http://jsben.ch/#/Y9jDP
pop vs slice: http://jsben.ch/#/tFaWe
match vs. regex vs. indexOf: http://jsben.ch/#/r9hBp
copy/clone array: http://jsben.ch/#/wQ9RU
Help to improve this thread, and give JS some speed! Post your benchmarks!
4 Likes
This tool is indeed a nice tool to benchmark JS.
Calculate 2D Distances: http://jsben.ch/#/Jxucs
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
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.