Skip to content

Instantly share code, notes, and snippets.

@PuKoren
Created April 12, 2017 17:08
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 PuKoren/ff51f42de8ccbf82476980bfdf905410 to your computer and use it in GitHub Desktop.
Save PuKoren/ff51f42de8ccbf82476980bfdf905410 to your computer and use it in GitHub Desktop.
Properties, does it count ? (https://jsbench.github.io/#ff51f42de8ccbf82476980bfdf905410) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Properties, does it count ?</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;
suite.add("for (var i = 0; i < 1000000; i++) {", function () {
for (var i = 0; i < 1000000; i++) {
const a = {
prop1: 5,
prop2: "",
prop3: false,
prop4: 1,
prop5: 0,
prop6: null,
prop7: "Hello",
prop8: 12345
};
}
});
suite.add("for (var i = 0; i < 1000000; i++) {", function () {
for (var i = 0; i < 1000000; i++) {
const a = {
prop1: 5,
prop2: 6,
prop3: 7,
prop4: 8,
prop5: 9,
prop6: 10,
prop7: 11,
prop8: 12345,
prop9: 123
};
}
});
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("Properties, does it count ?");
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