RLib Perf Example v0.4.0

node v8.17.0
version: 3.0.0
endpointsharetweet
Here is how to get started with RLib Perf
First we'll include libraries we need: rlib-perf and some functions to act as our control group.
const { Perf } = require("rlib-perf"); const _ = require("lodash"); const R = require("rlib");
We will be checking the performance of a iterable filter function.
function* iterableFilter(items, callback) { for (const item of items) { if (callback(item)) { yield item; } } }
We create a new instance of the performance runner.
const p = new Perf();
We can set up some information about our tests.
p.title = "Filter function comparison"; p.trials = 100; // Setup each test with some data p.setup( n => { return R.repeatFunc(1000 * (n + 1), idx => idx); }); // Label each trial for CSV purposes p.label(n => `${1000 * (n + 1)}`);
Next we define our individual tests
// Common filter function function filterFunc(n) { return n % 3 === 0; } p.test("native", state => { state.filter(filterFunc); }); p.test("lodash", state => { _.filter(state, filterFunc); }); p.test("rlib", state => { R.filter(state, filterFunc); }); p.test("iterable", state => { const it = iterableFilter(state, filterFunc); [...it]; });
Run our tests...
p.run();
And print out the results!
p.print();
Loading…

no comments

    sign in to comment