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 })
suite .add('gpu', () => { gpuKernel(gpuArg1, gpuArg2); }) .add('cpu', () => { cpuKernel(cpuArg1, cpuArg2); }) .on('cycle', (event) => { console.log(String(event.target)); }) .on('complete', function () { gpu.destroy(); cpu.destroy(); console.log('Fastest is ' + this.filter('fastest').map('name')); }) .run();
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 .from('books') .return('title', 'author', 'year').query }) .add('Sqorn - template string', function() { sq.from`books`.where`author = ${'Joe'}`.return`title, author, year`.query }) .add('Sqorn - express', function() { sq`books``author = ${'Joe'}``title, author, year`.query }) .add('Sqorn - extend', function() { sq.extend( sq.from`books`, ).query }) .add('Sqorn - raw', function() { sq.sql`select title, author, year from books where author = ${'Joe'}`.query }) .add('Knex', function() { knex .from('books') .toSQL() }) .add('Squel', function() { squel
new Benchmark.Suite() .add('a', function() { return source.map(s => double(s)).join(', ') }) .add('b', function() { let txt = '' for (let i = 0; i < source.length; ++i) { .add('c', function() { if (source.length === 0) return '' let txt = double(source[0]) .add('d', function() { let txt = '' for (let i = 0; i < source.length; ++i) {
new Benchmark.Suite() .add('sqorn complex', function() { sq .from(sq.txt`book`)
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('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 })
suite.add( 'forkCopy', () => { const obj = forkCopy(TEST_OBJ); delete obj.h; }, getOptions('forkCopy'), );
suite.add('event', function () { parser.encodePacket({ type: 'event' , name: 'woot' , endpoint: '' , args: [] }); });
function benchTryCatch (name, val) { const suite = createSuite(name) suite.add('JSON.parse (try-catch)', () => { try { JSON.parse(val) } catch (err) { return val } }) suite.add('sjson (try-catch)', () => { try { sjson.parse(val) } catch (err) { return val } }) suite.add('@hapi/bourne', () => { bourne.parse(val) }) suite.add('destr', () => { destr(val) }) suite.run() }
// add tests suite .add('gpu', () => { gpuKernel(a, b); }) .add('cpu', () => { cpuKernel(a, b); }) // add listeners .on('cycle', (event) => { console.log(String(event.target)); }) .on('complete', function () { gpu.destroy(); cpu.destroy(); console.log('Fastest is ' + this.filter('fastest').map('name')); }) .run({ async: false });
suite.add('event+ack', function () { parser.encodePacket({ type: 'json' , id: 1 , ack: 'data' , endpoint: '' , data: { a: 'b' } }); });