"use strict";
(function (factory) {
if (typeof Benchmark !== "undefined") {
factory(Benchmark);
} else {
factory(require("benchmark"));
}
})(function (Benchmark) {
var suite = new Benchmark.Suite;
suite.add("if (!window.xA) {window.xA = []}", function () {
if (!window.xA) {window.xA = []}
var x = xA
var i = 0
for (i = 0; i<255; i++){
x[i] = i
}
for (i; i<510; i++){
x[i] = i - 255
}
var result
for (i = 0; i<255; i++){
result = x[i]
}
});
suite.add("if (!window.x8_65536) {window.x8_65536 = new Uint8Array(65536)}", function () {
if (!window.x8_65536) {window.x8_65536 = new Uint8Array(65536)}
var x = x8_65536
var i = 0
for (i = 0; i<255; i++){
x[i] = i
}
for (i; i<510; i++){
x[i] = i - 255
}
var result
for (i = 0; i<255; i++){
result = x[i]
}
});
suite.add("if (!window.x8_1024) {window.x8_1024 = new Uint8Array(1024)}", function () {
if (!window.x8_1024) {window.x8_1024 = new Uint8Array(1024)}
var x = x8_1024
var i = 0
for (i = 0; i<255; i++){
x[i] = i
}
for (i; i<510; i++){
x[i] = i - 255
}
var result
for (i = 0; i<255; i++){
result = x[i]
}
});
suite.add("if (!window.x8) {window.x8 = new Uint8Array()}", function () {
if (!window.x8) {window.x8 = new Uint8Array()}
var x = x8
var i = 0
for (i = 0; i<255; i++){
x[i] = i
}
for (i; i<510; i++){
x[i] = i - 255
}
var result
for (i = 0; i<255; i++){
result = x[i]
}
});
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("typed array or not, with or without allocating size #jsbench #jsperf");
console.log(new Array(30).join("-"));
suite.run();
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>typed array or not, with or without allocating size #jsbench #jsperf</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>