I like to execute the following code...but as you can see - it will require 10 billion loops! So i was wondering - what you guys would suggest to make it spin faster?
The reason why - i need to like "brute force" to the best result - is because the most inner method do some complex calculation of some historical data - about 7 million rows from a DB...and the point by doing all this - is to find the best "setting" of the given parameters a-f...which gives the best result...
var a = 0.1; while(a <= 10) // 100 { var b = 0.1; while(b <= 10) // 100 { var c = 0.1; while(c <= 10) // 100 { var d = 0.1; while(d <= 10) // 100 { var e = 1; while(e <= 10) // 10 { var f = 1; while(f <= 10) // 10 10.000.000.000 { // Call at method which use all parameters and return the result of a given calculation //doSomeThing(a,b,c,d,e,f); f += 1; } e += 1; } d += 0.1; } c += 0.1; } b += 0.1; } a += 0.1; }
Break the loops into smaller chunks and fork processes using the core cluster module, processing each smaller chunk in a fork. The forks will run on separate threads, better leveraging the CPU.
https://nodejs.org/api/cluster.html#cluster_how_it_works
UPDATE. OK, don't use Cluster. Use the threads module instead - it will be much easier. https://www.npmjs.com/package/threads ...