From f32dba4a0373ad063a3aed1f0d676778bf8d5c01 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Wed, 12 Aug 2015 07:22:45 -0700 Subject: [PATCH] Clean up benchmarks --- perf/index.html | 2 +- perf/index.js | 103 +++++++++++++++++++++++++----------------------- 2 files changed, 54 insertions(+), 51 deletions(-) diff --git a/perf/index.html b/perf/index.html index b45cc04..b1a7bdd 100644 --- a/perf/index.html +++ b/perf/index.html @@ -9,6 +9,6 @@
Running tests...
-
Done!
+

Done!

diff --git a/perf/index.js b/perf/index.js index 123c2cf..aa8ecbf 100644 --- a/perf/index.js +++ b/perf/index.js @@ -1,11 +1,10 @@ +/* eslint no-console:0, no-unused-vars:0 */ const Benchmark = require('benchmark'); const u = require('../lib'); const _ = require('lodash'); const { curry2 } = require('../lib/util/curry'); -const suite = Benchmark.Suite(); // eslint-disable - const add = (x, y) => x + y; const fakeCurryAdd = x => y => x + y; const curryAdd = _.curry(add); @@ -15,54 +14,58 @@ const updeepCurry = curry2(add); const array = [0, 1, 2, 3, 4, 5]; // const doUpdate = u(x => x + 1); -suite -.add('updeep curry partial call', () => { - updeepCurry(3)(4); -}) -.add('lodash curry partial call', () => { - curryAdd(3)(4); -}) -.add('_.map', () => { - _.map(array, fakeCurryAdd(8)); -}) -.add('u.map', () => { - u.map(fakeCurryAdd(8), array); -}) -// .add('updeep curry', () => { -// u.map(curryAdd(3), array); -// }) -// .add('updeep big curry', () => { -// u.map(curryAdd(3), array); -// }) -// .add('no curry', () => { -// u.map(x => x + 1, array); -// }) -// .add('regular function call', () => { -// add(3, 4); -// }) -// .add('updeep full curry', () => { -// updeepCurry(3, 4); -// }) -// .add('updeep big full curry', () => { -// updeepCurryBig(3, 4); -// }) -// .add('curry full call', () => { -// curryAdd(3, 4); -// }) -// .add('fake curry', () => { -// fakeCurryAdd(3)(4); -// }) -// .add('_.map no changes', () => { -// _.map(array, x => x); -// }) -// .add('u.map no changes', () => { -// u.map(x => x, array); -// }) - -.on('cycle', (event) => { +function log(str) { if (typeof document !== 'undefined') { + console.log(str); const el = document.getElementById('perf'); - el.innerHTML = el.innerHTML + String(event.target) + '
'; + el.innerHTML = el.innerHTML + str; } -}) -.run({ async: true }); +} + +function createSuite(suiteName, tests) { + const suite = Benchmark.Suite(); // eslint-disable + + return () => { + log(`

${suiteName}

'); + }) + .run({ async: true }); + }; +} + + +const curryVsLodash = createSuite('Curry', { + 'updeep curry partial call': () => updeepCurry(3)(4), + 'lodash curry partial call': () => curryAdd(3)(4), +}); + +const mapVsLodash = createSuite('Map', { + '_.map': () => _.map(array, fakeCurryAdd(8)), + 'u.map': () => u.map(fakeCurryAdd(8), array), +}); + +const fn = (a, b, c, d, e) => a + b + c + d + e; +const fnControl = (a, b, c, d, e) => fn(a, b, c, d, e); +const fnApply = (...args) => fn(...args); +const fnDestructure = (...args) => { + const [a, b, c, d, e] = args; + return fn(a, b, c, d, e); +}; +const applyVsDestructure = createSuite('apply vs destructure', { + 'control': () => fnControl(1, 2, 3, 4, 5), + 'apply': () => fnApply(1, 2, 3, 4, 5), + 'destructure': () => fnDestructure(1, 2, 3, 4, 5), +}); + +// curryVsLodash(); +// mapVsLodash(); +applyVsDestructure();