new Benchmark.Suite('closure') .add('non-closure', function() { return nonClosure(['hi', 'bye', 'yay']) }) .add('closure', function() { return closure(['hi', 'bye', 'yay']) }) .on('cycle', function(event) { console.log(String(event.target)) }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')) }) .run({ async: false })
new Benchmark.Suite('last_string_index', { onStart: () => { str = Math.floor(Math.random() * 1000).toString(10) } }) .add('a', function() { return a.x === b.x }) .on('cycle', function(event) { console.log(String(event.target)) }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')) }) .run({ async: false })
new Benchmark.Suite('is_array') .add('Array.isArray', function() { return Array.isArray([]) }) .add('constructor.prototype === Array.prototype', function() { return [].constructor.prototype === Array.prototype }) .add('instanceof Array', function() { return [] instanceof Array }) .on('cycle', function(event) { console.log(String(event.target)) }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')) }) .run({ async: false })
new Benchmark.Suite() .add('Sqorn - args', function() { sq
new Benchmark.Suite() .add('sqorn complex', function() { sq
new Benchmark.Suite('last_string_index', { onStart: () => { str = Math.floor(Math.random() * 1000).toString(10) } }) .add('a', function() { return str.endsWith('$') }) .add('b', function() { return str.slice(-1) === '$' }) .add('c', function() { return str[str.length - 1] === '$' }) .on('cycle', function(event) { console.log(String(event.target)) }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')) }) .run({ async: false })
new Benchmark.Suite() .add('a', function() { return source.map(s => double(s)).join(', ')
new Benchmark.Suite('last_string_index', {}) .add('{}}', function() { const a = {} const b = {} const c = {} const d = {} const e = {} }) .on('new Object()', function(event) { const a = new Object() const b = new Object() const c = new Object() const d = new Object() const e = new Object() }) .on('new fn', function(event) { }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')) }) .run({ async: false })
new Benchmark.Suite('last_string_index', { onStart: () => { str = Math.floor(Math.random() * 1000).toString(10) } }) .add('obj', function() { const { x, y } = obj() return x + y }) .add('arr', function() { const [x, y] = arr() return x + y }) .add('robj', function() { const { x, y } = robj() return x + y }) .add('rarr', function() { const [x, y] = rarr() return x + y }) .on('cycle', function(event) { console.log(String(event.target)) }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').map('name')) }) .run({ async: false })
const runBenchmarks = ({ downloadSizes }) => { const tableHead = [ ['Module', 'OPS', 'RME', 'Samples'], ['---------------', '----------', '----------', '----------'] ] const results = {} downloadSizes.map(s => { results[s.uri] = [...tableHead] }) const suite = Benchmark.Suite() downloadSizes.map(o => addTestCases(suite, o)) suite.on('cycle', onCycle(suite.length, downloadSizes, results)) suite.on('complete', onComplete(downloadSizes, results)) suite.run({ async: true }) }
function doSuite(libName, fn) { console.log(`## ${libName}`); if (fileWriter) { fileWriter.newLine(); fileWriter.writeTableElement(libName); } const Suite = new Benchmark.Suite(); const suite = Suite .on('cycle', function (event) { console.log(String(event.target)); if (fileWriter) { fileWriter.writeTableElement(computeNumber(event.target.hz)); } }); const arrays = []; for (let i = 0; i < elements.length; i++) { arrays.push(new Array(elements[i]).fill(0).map((e, i) => i % 2)); suite.add(`${elements.length}`, function () { fn(arrays[i]); }); } suite.run({ async: false }); }
function computeBenchmarkSuite() { return new Benchmark.Suite() .on('cycle', function (event) { console.log(`\t\t${event.target}`); }) .on('complete', function () { const fasterName = this.filter('fastest').map('name'), nativeTime = this.shift(), sanicTime = this.shift(); if (fileWriter) fileWriter.writeTableElement( `x ${Math.round(sanicTime.hz / nativeTime.hz * 100) / 100}` ); console.log(`\t\t-> Fastest is ${fasterName} (x ${sanicTime.hz / nativeTime.hz})`); }); }
const createSuite = () => new Benchmark.Suite() .on("cycle", event => { if (event.target.error) { event.target.error = { stack: event.target.error.stack }; } bb.add(event.target); }) .on("complete", () => { bb.log(); runNextTest(); })
function run (root) { const suite = Benchmark.Suite() suite.add('walk-sync', function () { walkSync(root) }).add('klaw-sync', function () { klawSync(root) }).on('error', function (er) { return er }).on('cycle', function (ev) { console.log(String(ev.target)) }).on('complete', function () { console.log('Fastest is ' + this.filter('fastest').map('name')) }).run() }
new Benchmark.Suite() .add('esotope', function () { cycle(esotope); }) .add('escodegen', function () { cycle(escodegen); }) .add('old', function () { cycle(old); }) .on('start', function () { console.log('Benchmarking...') }) .on('cycle', function (event) { console.log(event.target.toString()); }) .on('complete', function () { console.log('Fastest is ' + this.filter('fastest').pluck('name')); console.log('esotope is x' + (this[0].hz / this[1].hz).toFixed(2) + ' times faster vs escodegen.'); }) .run();