Last active
November 21, 2017 18:15
-
-
Save stefnotch/98fb469d0ced38f9a834f1be3319abcd to your computer and use it in GitHub Desktop.
DQ Test (https://jsbench.github.io/#98fb469d0ced38f9a834f1be3319abcd) #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>DQ Test</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 () { | |
function createA() { | |
return [new Float32Array([1,2,3,4]), new Float32Array([5,6,7,8])]; | |
} | |
function createB() { | |
return new Float32Array([1,2,3,4, 5, 6, 7, 8]); | |
} | |
var a = createA(); | |
var b = createB(); | |
var aa = []; | |
var bb = []; | |
for(var i = 0; i < 1000; i++) { | |
aa.push(createA()); | |
bb.push(createB()); | |
} | |
}; | |
suite.add("a Creation test", function () { | |
//a Creation test | |
var x = createA(); | |
}); | |
suite.add("b Creation test, over twice as fast (as expected)", function () { | |
//b Creation test, over twice as fast (as expected) | |
var x = createB(); | |
}); | |
suite.add("a reading/writing test", function () { | |
//a reading/writing test | |
a[0][0]++; | |
a[0][1]++; | |
a[0][2]++; | |
a[0][3]++; | |
a[1][0]++; | |
a[1][1]++; | |
a[1][2]++; | |
a[1][3]++; | |
}); | |
suite.add("b reading/writing test", function () { | |
//b reading/writing test | |
b[0]++; | |
b[1]++; | |
b[2]++; | |
b[3]++; | |
b[4]++; | |
b[5]++; | |
b[6]++; | |
b[7]++; | |
}); | |
suite.add("a random reading/writing test", function () { | |
//a random reading/writing test | |
a[0][(Math.random()*4)<<0]++; | |
a[1][(Math.random()*4)<<0]++; | |
}); | |
suite.add("b random reading/writing test", function () { | |
//b random reading/writing test | |
b[(Math.random()*8)<<0]++; | |
b[(Math.random()*8)<<0]++; | |
}); | |
suite.add("a array random reading/writing test", function () { | |
//a array random reading/writing test | |
aa[(Math.random()*1000)<<0][0][0]++; | |
aa[(Math.random()*1000)<<0][0][1]++; | |
aa[(Math.random()*1000)<<0][0][2]++; | |
aa[(Math.random()*1000)<<0][0][3]++; | |
aa[(Math.random()*1000)<<0][1][0]++; | |
aa[(Math.random()*1000)<<0][1][1]++; | |
aa[(Math.random()*1000)<<0][1][2]++; | |
aa[(Math.random()*1000)<<0][1][3]++; | |
}); | |
suite.add("b array random reading/writing test", function () { | |
//b array random reading/writing test | |
bb[(Math.random()*1000)<<0][0]++; | |
bb[(Math.random()*1000)<<0][1]++; | |
bb[(Math.random()*1000)<<0][2]++; | |
bb[(Math.random()*1000)<<0][3]++; | |
bb[(Math.random()*1000)<<0][4]++; | |
bb[(Math.random()*1000)<<0][5]++; | |
bb[(Math.random()*1000)<<0][6]++; | |
bb[(Math.random()*1000)<<0][7]++; | |
}); | |
suite.add("a array random reading/writing test", function () { | |
//a array random reading/writing test | |
var x = (Math.random()*(1000-11))<<0; | |
aa[x][0][0]++; | |
aa[x+1][0][1]++; | |
aa[x+2][0][2]++; | |
aa[x+3][0][3]++; | |
aa[x+5][1][0]++; | |
aa[x+6][1][1]++; | |
aa[x+9][1][2]++; | |
aa[x+11][1][3]++; | |
}); | |
suite.add("b array random reading/writing test", function () { | |
//b array random reading/writing test | |
var x = (Math.random()*(1000-11))<<0; | |
bb[x][0]++; | |
bb[x+1][1]++; | |
bb[x+2][2]++; | |
bb[x+3][3]++; | |
bb[x+5][4]++; | |
bb[x+6][5]++; | |
bb[x+9][6]++; | |
bb[x+11][7]++; | |
}); | |
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("DQ Test"); | |
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