Last active
July 25, 2019 09:17
-
-
Save warpech/4492c4417b176808179d255e79ead076 to your computer and use it in GitHub Desktop.
Nested block overhead (http://jsbench.github.io/#4492c4417b176808179d255e79ead076) #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>Nested block overhead</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 inc(x) { | |
return x + 1; | |
} | |
const incES6 = x => x + 1; | |
}; | |
suite.add("let a = 1;", function () { | |
let a = 1; | |
let b = a + 1; | |
let c = b + 1; | |
let d = c + 1; | |
let e = d + 1; | |
let f = e + 1; | |
let g = f + 1; | |
let h = g + 1; | |
let i = h + 1; | |
let j = i + 1; | |
}); | |
suite.add("{", function () { | |
{ | |
let a = 1; | |
{ | |
let b = a + 1; | |
{ | |
let c = b + 1; | |
{ | |
let d = c + 1; | |
{ | |
let e = d + 1; | |
{ | |
let f = e + 1; | |
{ | |
let g = f + 1; | |
{ | |
let h = g + 1; | |
{ | |
let i = h + 1; | |
{ let j = i + 1; } | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}); | |
suite.add("let a = inc(0);", function () { | |
let a = inc(0); | |
let b = inc(a); | |
let c = inc(b); | |
let d = inc(c); | |
let e = inc(d); | |
let f = inc(e); | |
let g = inc(f); | |
let h = inc(g); | |
let i = inc(h); | |
let j = inc(i); | |
}); | |
suite.add("let a = incES6(0);", function () { | |
let a = incES6(0); | |
let b = incES6(a); | |
let c = incES6(b); | |
let d = incES6(c); | |
let e = incES6(d); | |
let f = incES6(e); | |
let g = incES6(f); | |
let h = incES6(g); | |
let i = incES6(h); | |
let j = incES6(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("Nested block overhead"); | |
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