Skip to content

Instantly share code, notes, and snippets.

@Alzy
Last active March 22, 2018 08:34
Show Gist options
  • Select an option

  • Save Alzy/496aca8a6430ffdae977ae3ec62a2a9c to your computer and use it in GitHub Desktop.

Select an option

Save Alzy/496aca8a6430ffdae977ae3ec62a2a9c to your computer and use it in GitHub Desktop.
Aaron Becker's method of measuring/guessing client's cpu speed
// https://stackoverflow.com/questions/15464896/get-cpu-gpu-memory-information/42143572#42143572
// https://stackoverflow.com/users/6179827/aaron-becker
var _speedconstant = 8.9997e-9; //if speed=(c*a)/t, then constant=(s*t)/a and time=(a*c)/s
var d = new Date();
var amount = 150000000;
var estprocessor = 1.7; //average processor speed, in GHZ
console.log("JSBenchmark by Aaron Becker, running loop "+amount+" times. Estimated time (for "+estprocessor+"ghz processor) is "+(Math.round(((_speedconstant*amount)/estprocessor)*100)/100)+"s");
for (var i = amount; i>0; i--) {}
var newd = new Date();
var accnewd = Number(String(newd.getSeconds())+"."+String(newd.getMilliseconds()));
var accd = Number(String(d.getSeconds())+"."+String(d.getMilliseconds()));
var di = accnewd-accd;
//console.log(accnewd,accd,di);
if (d.getMinutes() != newd.getMinutes()) {
di = (60*(newd.getMinutes()-d.getMinutes()))+di}
spd = ((_speedconstant*amount)/di);
console.log("Time: "+Math.round(di*1000)/1000+"s, estimated speed: "+Math.round(spd*1000)/1000+"GHZ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment