-
-
Save lll000111/ef5533b8dfb56af8a289792f21760bcc to your computer and use it in GitHub Desktop.
Untitled benchmark #jsbench #jsperf (http://jsbench.github.io/#ef5533b8dfb56af8a289792f21760bcc) #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>Untitled benchmark #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> |
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 isStooge(name) { | |
const STOOGES = ['Larry', 'Curly', 'Moe']; | |
return STOOGES.includes(name); | |
}; | |
const isStooge2 = (function() { | |
const STOOGES = ['Larry', 'Curly', 'Moe']; | |
return (name) => STOOGES.includes(name); | |
})(); | |
function isStooge3(name) { | |
return isStooge3.STOOGES.includes(name); | |
} | |
isStooge3.STOOGES = ['Larry', 'Curly', 'Moe']; | |
class StoogeChecker { | |
static isStooge(name) { | |
return StoogeChecker.STOOGES.includes(name); | |
} | |
} | |
StoogeChecker.STOOGES = ['Larry', 'Curly', 'Moe']; | |
const STOOGES = ['Larry', 'Curly', 'Moe']; | |
function isStooge4(name) { | |
return STOOGES.includes(name); | |
} | |
}; | |
suite.add("isStooge('Moe');", function () { | |
isStooge('Moe'); | |
isStooge('Joe'); | |
isStooge('Larry'); | |
isStooge('Barry'); | |
isStooge('Curly'); | |
isStooge('Burly'); | |
}); | |
suite.add("isStooge2('Moe');", function () { | |
isStooge2('Moe'); | |
isStooge2('Joe'); | |
isStooge2('Larry'); | |
isStooge2('Barry'); | |
isStooge2('Curly'); | |
isStooge2('Burly'); | |
}); | |
suite.add("isStooge3('Moe');", function () { | |
isStooge3('Moe'); | |
isStooge3('Joe'); | |
isStooge3('Larry'); | |
isStooge3('Barry'); | |
isStooge3('Curly'); | |
isStooge3('Burly'); | |
}); | |
suite.add("StoogeChecker.isStooge('Moe');", function () { | |
StoogeChecker.isStooge('Moe'); | |
StoogeChecker.isStooge('Joe'); | |
StoogeChecker.isStooge('Larry'); | |
StoogeChecker.isStooge('Barry'); | |
StoogeChecker.isStooge('Curly'); | |
StoogeChecker.isStooge('Burly'); | |
}); | |
suite.add("isStooge4('Moe');", function () { | |
isStooge4('Moe'); | |
isStooge4('Joe'); | |
isStooge4('Larry'); | |
isStooge4('Barry'); | |
isStooge4('Curly'); | |
isStooge4('Burly'); | |
}); | |
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 #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