-
-
Save RobertAKARobin/69e72becc163a625fbec3f1d773ea0b7 to your computer and use it in GitHub Desktop.
Untitled benchmark #jsbench #jsperf (http://jsbench.github.io/#69e72becc163a625fbec3f1d773ea0b7) #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']; | |
function StoogeChecker2(){} | |
StoogeChecker2.STOOGES = ['Larry', 'Curly', 'Moe']; | |
StoogeChecker2.isStooge = function(name){ | |
return StoogeChecker2.STOOGES.includes(name); | |
} | |
const StoogeChecker3 = Object.create({}, { | |
STOOGES: { | |
value: ['Larry', 'Curly', 'Moe'] | |
}, | |
isStooge: { | |
value: function(name){ | |
return StoogeChecker3.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("StoogeChecker2.isStooge('Moe');", function () { | |
StoogeChecker2.isStooge('Moe'); | |
StoogeChecker2.isStooge('Joe'); | |
StoogeChecker2.isStooge('Larry'); | |
StoogeChecker2.isStooge('Barry'); | |
StoogeChecker2.isStooge('Curly'); | |
StoogeChecker2.isStooge('Burly'); | |
}); | |
suite.add("StoogeChecker3.isStooge('Moe');", function () { | |
StoogeChecker3.isStooge('Moe'); | |
StoogeChecker3.isStooge('Joe'); | |
StoogeChecker3.isStooge('Larry'); | |
StoogeChecker3.isStooge('Barry'); | |
StoogeChecker3.isStooge('Curly'); | |
StoogeChecker3.isStooge('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