I wrote this quick script to get the cpu speed:
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");
Note that this depends on browser tabs, memory use, etc. but I found it pretty accurate if you only run it once, say at the loading of a page.
This may not be accurate for desktop devices, especially PCs, but I use it in my website only when other solutions like the first one fail, for getting the average speed of mobile devices (allows me to estimate cores used) using only client-side JS. It may not be the best, but it does pretty well.
If you would like you can change the _speedconstant to change the speed, just calculate it with the equation (knowncpuspeed*knowntimetocomplete)/knowncycles. Hope you find this useful!
UPDATE 10/19/17: Changed _speedconstant for the new chrome V8 JS engine and added section about what I use it for.