Skip to content

Instantly share code, notes, and snippets.

@wooandoo
Last active December 2, 2020 12:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wooandoo/ca0e61ceccb1482e77de8392fb028340 to your computer and use it in GitHub Desktop.
Save wooandoo/ca0e61ceccb1482e77de8392fb028340 to your computer and use it in GitHub Desktop.
native vs lodash vs ramda #jsbench #jsperf (http://jsbench.github.io/#ca0e61ceccb1482e77de8392fb028340) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>native vs lodash vs ramda #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 () {
function dynamicallyLoadScript(url) {
var script = document.createElement("script"); // create a script DOM node
script.src = url; // set its src to the provided URL
document.head.appendChild(script); // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
}
dynamicallyLoadScript("https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js")
dynamicallyLoadScript("https://cdn.jsdelivr.net/npm/ramda@0.27.1/dist/ramda.min.js")
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const is_event = value => value % 2 === 0
const result = value => ({ name: `value = ${value}` })
};
suite.add("let x = array.filter(is_event).map(result)", function () {
let x = array.filter(is_event).map(result)
// console.log("native", x)
});
suite.add("let x = _.map(", function () {
let x = _.map(
_.filter(array, is_event),
result
)
// console.log("lodash", x)
});
suite.add("let x = R.map(", function () {
let x = R.map(
result,
R.filter(is_event, array)
)
// console.log("ramda", x)
});
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("native vs lodash vs ramda #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