Skip to content

Instantly share code, notes, and snippets.

@tivac
Last active June 8, 2022 18:24
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 tivac/8b564bf629879c3e243bc62943981cc1 to your computer and use it in GitHub Desktop.
Save tivac/8b564bf629879c3e243bc62943981cc1 to your computer and use it in GitHub Desktop.
inner vs outer fn #jsbench #jsperf (http://jsbench.github.io/#8b564bf629879c3e243bc62943981cc1) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>inner vs outer fn #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>
"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 _hexify = (num) => (num >>> 0).toString(16);
const toString = (guid) =>
`${_hexify(guid.A)}-${_hexify(guid.B)}-${_hexify(guid.C)}-${_hexify(guid.D)}`;
const toStringInline = (guid) => {
const hexy = (num) => (num >>> 0).toString(16);
return `${hexy(guid.A)}-${hexy(guid.B)}-${hexy(guid.C)}-${hexy(guid.D)}`;
}
};
suite.add("toString({ A : 2897185746, B : 1248873899, C : 2220319872, D : 3878081850 });", function () {
toString({ A : 2897185746, B : 1248873899, C : 2220319872, D : 3878081850 });
});
suite.add("toStringInline({ A : 2897185746, B : 1248873899, C : 2220319872, D : 3878081850 });", function () {
toStringInline({ A : 2897185746, B : 1248873899, C : 2220319872, D : 3878081850 });
});
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("inner vs outer fn #jsbench #jsperf");
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