Skip to content

Instantly share code, notes, and snippets.

@areknawo
Created April 22, 2018 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save areknawo/e9377e641c8de7db394a2b9766f6d4db to your computer and use it in GitHub Desktop.
Save areknawo/e9377e641c8de7db394a2b9766f6d4db to your computer and use it in GitHub Desktop.
Untitled benchmark (https://jsbench.github.io/#e9377e641c8de7db394a2b9766f6d4db) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</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>
"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 tileToQuadkey(tile) {
var index = '';
for (var z = tile[2]; z > 0; z--) {
var b = 0;
var mask = 1 << (z - 1);
if ((tile[0] & mask) !== 0) b++;
if ((tile[1] & mask) !== 0) b += 2;
index += b.toString();
}
console.log(index)
return index;
}
function tileToKey(tile){
return tile.join('|');
}
function quadkeyToTile(quadkey) {
var x = 0;
var y = 0;
var z = quadkey.length;
for (var i = z; i > 0; i--) {
var mask = 1 << (i - 1);
var q = +quadkey[z - i];
if (q === 1) x |= mask;
if (q === 2) y |= mask;
if (q === 3) {
x |= mask;
y |= mask;
}
}
return [x, y, z];
}
function keyToTile(key){
return key.split('|');
}
var tile = [1562,1344,16];
};
suite.add("quadkeyToTile('0000031202011010');", function () {
quadkeyToTile('0000031202011010');
});
suite.add("keyToTile('1562|1344|16');", function () {
keyToTile('1562|1344|16');
});
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("Untitled benchmark");
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