Created
April 19, 2017 08:05
-
-
Save TimothyGu/ae4e21e34182f589454f368be41bd56e to your computer and use it in GitHub Desktop.
64bit comparison (https://jsbench.github.io/#ae4e21e34182f589454f368be41bd56e) #jsbench #jsperf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<title>64bit comparison</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script> | |
<script src="./suite.js"></script> | |
</head> | |
<body> | |
<h1>Open the console to view the results</h1> | |
<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
(function (factory) { | |
if (typeof Benchmark !== "undefined") { | |
factory(Benchmark); | |
} else { | |
factory(require("benchmark")); | |
} | |
})(function (Benchmark) { | |
var suite = new Benchmark.Suite; | |
Benchmark.prototype.setup = function () { | |
const strings = Array(1024) | |
.fill(0) | |
.map(() => { | |
let buf = new Uint8Array(8); | |
crypto.getRandomValues(buf); | |
return buf.map((c) => c.toString(16)).join(''); | |
}); | |
const arrays = Array(1024) | |
.fill(0) | |
.map(() => { | |
let buf = new Uint32Array(2); | |
crypto.getRandomValues(buf); | |
return buf; | |
}); | |
const numbers = Array(1024) | |
.fill(0) | |
.map(() => { | |
let buf = new Uint32Array(2); | |
crypto.getRandomValues(buf); | |
return buf[0] * 0xffffffff + buf[1]; | |
}); | |
}; | |
suite.add("var noOptimizeAway = true;", function () { | |
var noOptimizeAway = true; | |
for (var i = 0; i < strings.length; i++) { | |
for (var j = 0; j < strings.length; j++) { | |
noOptimizeAway = strings[i] === strings[j]; | |
} | |
} | |
}); | |
suite.add("var noOptimizeAway = true;", function () { | |
var noOptimizeAway = true; | |
for (var i = 0; i < arrays.length; i++) { | |
for (var j = 0; j < arrays.length; j++) { | |
noOptimizeAway = arrays[i][0] === arrays[j][0] && | |
arrays[i][1] === arrays[j][1]; | |
} | |
} | |
}); | |
suite.add("var noOptimizeAway = true;", function () { | |
var noOptimizeAway = true; | |
for (var i = 0; i < numbers.length; i++) { | |
for (var j = 0; j < numbers.length; j++) { | |
noOptimizeAway = numbers[i] === numbers[j]; | |
} | |
} | |
}); | |
suite.on("cycle", function (evt) { | |
console.log(" - " + evt.target); | |
}); | |
suite.on("complete", function (evt) { | |
console.log(new Array(30).join("-")); | |
var results = evt.currentTarget.sort(function (a, b) { | |
return b.hz - a.hz; | |
}); | |
results.forEach(function (item) { | |
console.log((idx + 1) + ". " + item); | |
}); | |
}); | |
console.log("64bit comparison"); | |
console.log(new Array(30).join("-")); | |
suite.run(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment