How to use buildBenchmark method in Best

Best JavaScript code snippet using best

best-build.spec.ts

Source:best-build.spec.ts Github

copy

Full Screen

...34describe('buildBenchmark', () => {35 test('generating index.js and index.html', async () => {36 const benchmarkOutput = tempDir();37 const hash = GLOBAL_CONFIG.gitInfo.lastCommit.hash;38 await buildBenchmark(39 path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),40 {41 benchmarkOutput,42 projectName,43 rootDir44 },45 GLOBAL_CONFIG,46 MOCK_MESSAGER,47 );48 expect(fs.statSync(`${benchmarkOutput}/${projectName}/single-file_${hash}/artifacts`).isDirectory()).toBe(true);49 expect(fs.statSync(`${benchmarkOutput}/${projectName}/single-file_${hash}/artifacts/single-file.html`).isFile()).toBe(true);50 expect(fs.statSync(`${benchmarkOutput}/${projectName}/single-file_${hash}/artifacts/single-file.js`).isFile()).toBe(true);51 });52 test('build output', async () => {53 const hash = GLOBAL_CONFIG.gitInfo.lastCommit.hash;54 const { benchmarkName, benchmarkEntry, benchmarkFolder, benchmarkSignature } = await buildBenchmark(55 path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),56 {57 benchmarkOutput: tempDir(),58 projectName,59 rootDir60 },61 GLOBAL_CONFIG,62 MOCK_MESSAGER,63 );64 expect(benchmarkName).toBe('single-file');65 expect(benchmarkFolder.endsWith(`single-file_${hash}`)).toBe(true);66 expect(fs.existsSync(benchmarkFolder)).toBe(true);67 expect(benchmarkEntry.endsWith(`single-file_${hash}/artifacts/single-file.html`)).toBe(true);68 expect(fs.existsSync(benchmarkEntry)).toBe(true);69 expect(typeof benchmarkSignature).toBe('string');70 });71 test('calling messager before and after the build', async () => {72 const messager = {73 onBenchmarkBuildStart: jest.fn(),74 onBenchmarkBuildEnd: jest.fn(),75 log: jest.fn76 };77 await buildBenchmark(78 path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),79 {80 benchmarkOutput: tempDir(),81 projectName,82 rootDir83 },84 GLOBAL_CONFIG,85 messager,86 );87 expect(messager.onBenchmarkBuildStart).toHaveBeenCalled();88 expect(messager.onBenchmarkBuildEnd).toHaveBeenCalled();89 });90 test('plugin receives options when required', async () => {91 expect.hasAssertions();92 const PLUGIN_OPTIONS = {93 foo: 'bar',94 };95 jest.doMock(96 'build-plugin-opts',97 () => {98 return options => {99 expect(options).toBe(PLUGIN_OPTIONS);100 return {};101 };102 },103 {104 virtual: true,105 },106 );107 await buildBenchmark(108 path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),109 {110 benchmarkOutput: tempDir(),111 projectName,112 plugins: [['build-plugin-opts', PLUGIN_OPTIONS]],113 rootDir114 },115 GLOBAL_CONFIG,116 MOCK_MESSAGER,117 );118 });119 test('plugin hooks into rollup lifecycle hooks', async () => {120 const entry = path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js');121 const loaded = [];122 const transformed = [];123 jest.doMock(124 'build-plugin-hooks',125 () => {126 return () => {127 return {128 load(id) {129 if (id.endsWith('single-file.js')) {130 loaded.push(id);131 return '/* empty */';132 }133 },134 transform(src, id) {135 transformed.push(id);136 return src;137 }138 };139 };140 },141 {142 virtual: true,143 },144 );145 await buildBenchmark(146 path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'),147 {148 benchmarkOutput: tempDir(),149 projectName,150 plugins: ['build-plugin-hooks'],151 rootDir152 },153 GLOBAL_CONFIG,154 MOCK_MESSAGER,155 );156 expect(loaded.some(file => file === entry)).toBe(true);157 expect(transformed.some(file => file === entry)).toBe(true);158 });159 test(`throw if bare module specifiers can't be resolved`, async () => {160 await expect(() => buildBenchmark(161 path.resolve(__dirname, 'fixtures', 'error-missing-external', 'error-missing-external.js'),162 {163 benchmarkOutput: tempDir(),164 projectName,165 rootDir166 },167 GLOBAL_CONFIG,168 MOCK_MESSAGER,169 )).rejects.toHaveProperty(170 'message',171 expect.stringMatching(/'x\/missing' is imported by .*, but could not be resolved – treating it as an external dependency/)172 )173 });174});

Full Screen

Full Screen

bench.js

Source:bench.js Github

copy

Full Screen

...5 * @param {number} order Order6 * @param {number} size Tree size7 * @param {boolean=} skipAsserted Skips assertions if set to true8 */9function buildBenchmark(order, size, skipAsserted) {10 var Tree, tree;11 var max = size* 2;12 return {13 "init": function(test) {14 Tree = btree.create(order);15 tree = new Tree();16 test.done();17 },18 "put": {19 20 "asserted": skipAsserted ? null : {21 22 "notExisting": function(test) {23 for (var i=0; i<max; i+=2) {...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

...16fs.writeFileSync(17 path.join(__dirname, 'input.txt'),18 Array.from({ length: 5000 }, () => str(Math.ceil(Math.random() * 5000))).join('\n'),19);20function buildBenchmark(createStream: Function) {21 return function run(cb: Function) {22 const input = fs.createReadStream(path.join(__dirname, 'input.txt'), {23 highWaterMark: hwm,24 });25 const stream = createStream();26 let lines = 0;27 stream.on('data', () => { lines += 1; });28 stream.on('end', () => {29 assert.equal(lines, 5000);30 cb();31 });32 if (stream instanceof fs.WriteStream) input.on('end', cb);33 input.pipe(stream);34 };35}36function bench(steps: Steps, count: number): Promise<void> {37 console.log(['name', 'time', 'stdev'].join('\t'));38 const times = new Map();39 return Object.keys(steps).reduce((p, step: string) => {40 const results: Array<number> = [];41 times.set(step, results);42 for (let i = 0; i < count; i += 1) {43 p = p.then(() => new Promise((resolve, reject) => {44 const start = process.hrtime();45 try {46 steps[step]((err?: Error) => {47 if (err) return reject(err);48 const [sec, ns] = process.hrtime(start);49 results.push(Math.ceil(sec * 1000 + ns / 1e6));50 process.nextTick(resolve);51 });52 } catch (e) {53 reject(e);54 }55 }));56 }57 return p.then(() => {58 const avg = results.reduce((a, b) => a + b, 0) / count;59 const stdev = results.map((r) => r - avg).reduce((a, b) => a + b * b, 0) / (count - 1);60 console.log([step, avg.toFixed(2), Math.sqrt(stdev).toFixed(2)].join('\t'));61 // allow the GC to do its thing62 return new Promise((resolve) => setTimeout(resolve, 1000));63 }, (err: Error) => {64 console.log(step, 'failed with', err);65 });66 }, Promise.resolve());67}68bench({69 '/dev/null': buildBenchmark(() => fs.createWriteStream('/dev/null')),70 split2: buildBenchmark(() => split2()),71 split: buildBenchmark(() => split()),72 'binary-split': buildBenchmark(() => binarySplit()),73 splitly: buildBenchmark(() => Splitly.createStream()),74 byline: buildBenchmark(() => byline.createStream()),...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var best = require('best');2var bm = best.buildBenchmark('test4');3bm.start();4bm.stop();5bm.printReport();6var best = require('best');7var bm = best.buildBenchmark('test5');8bm.start();9bm.stop();10bm.printReport();11var best = require('best');12var bm = best.buildBenchmark('test6');13bm.start();14bm.stop();15bm.printReport();16var best = require('best');17var bm = best.buildBenchmark('test7');18bm.start();19bm.stop();20bm.printReport();21var best = require('best');22var bm = best.buildBenchmark('test8');23bm.start();24bm.stop();25bm.printReport();26var best = require('best');27var bm = best.buildBenchmark('test9');28bm.start();29bm.stop();30bm.printReport();31var best = require('best');32var bm = best.buildBenchmark('test10');33bm.start();34bm.stop();35bm.printReport();36var best = require('best');37var bm = best.buildBenchmark('test11');38bm.start();39bm.stop();40bm.printReport();41var best = require('best');42var bm = best.buildBenchmark('test12');43bm.start();44bm.stop();45bm.printReport();46var best = require('best');47var bm = best.buildBenchmark('test13');48bm.start();49bm.stop();50bm.printReport();

Full Screen

Using AI Code Generation

copy

Full Screen

1var Best = require('./best.js');2var test = Best.buildBenchmark("test", 10, function() {3 return Best.buildBenchmark("test2", 10, function() {4 return Best.buildBenchmark("test3", 10, function() {5 return Best.buildBenchmark("test4", 10, function() {6 return Best.buildBenchmark("test5", 10, function() {7 return Best.buildBenchmark("test6", 10, function() {8 return Best.buildBenchmark("test7", 10, function() {9 return Best.buildBenchmark("test8", 10, function() {10 return Best.buildBenchmark("test9", 10, function() {11 return Best.buildBenchmark("test10", 10, function() {12 return Best.buildBenchmark("test11", 10, function() {13 return Best.buildBenchmark("test12", 10, function() {14 return Best.buildBenchmark("test13", 10, function() {15 return Best.buildBenchmark("test14", 10, function() {16 return Best.buildBenchmark("test15", 10, function() {17 return Best.buildBenchmark("test16", 10, function() {18 return Best.buildBenchmark("test17", 10, function() {19 return Best.buildBenchmark("test18", 10, function() {20 return Best.buildBenchmark("test19", 10, function() {21 return Best.buildBenchmark("test20", 10, function() {22 return Best.buildBenchmark("test21", 10, function() {23 return Best.buildBenchmark("test22", 10, function() {24 return Best.buildBenchmark("test23", 10, function() {25 return Best.buildBenchmark("test24", 10, function() {26 return Best.buildBenchmark("test25", 10, function() {27 return Best.buildBenchmark("test26", 10, function() {28 return Best.buildBenchmark("test27", 10, function() {29 return Best.buildBenchmark("test28", 10, function() {30 return Best.buildBenchmark("test29", 10, function() {31 return Best.buildBenchmark("test30", 10, function() {32 return Best.buildBenchmark("test31", 10, function() {33 return Best.buildBenchmark("test32", 10, function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1var best = require('best');2var suite = new best.Suite({3 setup: function() {4 this.foo = 'bar';5 },6 teardown: function() {7 this.foo = null;8 }9});10suite.add({11 fn: function() {12 return this.foo;13 }14});15suite.add({16 fn: function() {17 return this.foo;18 }19});20suite.run();21var best = require('best');22var suite = new best.Suite({23 setup: function() {24 this.foo = 'bar';25 },26 teardown: function() {27 this.foo = null;28 }29});30suite.add({31 fn: function() {32 return this.foo;33 }34});35suite.add({36 fn: function() {37 return this.foo;38 }39});40suite.run();41var best = require('best');42var suite = new best.Suite({43 setup: function() {44 this.foo = 'bar';45 },46 teardown: function() {47 this.foo = null;48 }49});50suite.add({51 fn: function() {52 return this.foo;53 }54});55suite.add({56 fn: function() {57 return this.foo;58 }59});60suite.run();61var best = require('best');62var suite = new best.Suite({63 setup: function() {64 this.foo = 'bar';65 },66 teardown: function() {67 this.foo = null;68 }69});70suite.add({71 fn: function() {72 return this.foo;73 }74});75suite.add({

Full Screen

Using AI Code Generation

copy

Full Screen

1var best = require('best');2var benchmark = best.buildBenchmark('test4', 'this is a test');3benchmark.start();4benchmark.stop();5benchmark.save();6var best = require('best');7var benchmark = best.buildBenchmark('test5', 'this is a test');8benchmark.start();9benchmark.stop();10benchmark.save();11var best = require('best');12var benchmark = best.buildBenchmark('test6', 'this is a test');13benchmark.start();14benchmark.stop();15benchmark.save();16var best = require('best');17var benchmark = best.buildBenchmark('test7', 'this is a test');18benchmark.start();19benchmark.stop();20benchmark.save();21var best = require('best');22var benchmark = best.buildBenchmark('test8', 'this is a test');23benchmark.start();24benchmark.stop();25benchmark.save();26var best = require('best');27var benchmark = best.buildBenchmark('test9', 'this is a test');28benchmark.start();29benchmark.stop();30benchmark.save();31var best = require('best');32var benchmark = best.buildBenchmark('test10', 'this is a test');33benchmark.start();34benchmark.stop();35benchmark.save();36var best = require('best');37var benchmark = best.buildBenchmark('test11', 'this is a test');38benchmark.start();39benchmark.stop();40benchmark.save();41var best = require('best');42var benchmark = best.buildBenchmark('test12', 'this is a test');43benchmark.start();44benchmark.stop();45benchmark.save();46var best = require('best');

Full Screen

Using AI Code Generation

copy

Full Screen

1var Best = require('best');2var best = new Best();3var test4 = best.buildBenchmark('test4', function() {4}, 1000);5test4.run();6var Best = require('best');7var best = new Best();8var test5 = best.buildBenchmark('test5', function() {9}, 1000);10test5.run();11var Best = require('best');12var best = new Best();13var test6 = best.buildBenchmark('test6', function() {14}, 1000);15test6.run();16var Best = require('best');17var best = new Best();18var test7 = best.buildBenchmark('test7', function() {19}, 1000);20test7.run();21var Best = require('best');22var best = new Best();23var test8 = best.buildBenchmark('test8', function() {24}, 1000);25test8.run();26var Best = require('best');27var best = new Best();28var test9 = best.buildBenchmark('test9', function() {29}, 1000);30test9.run();31var Best = require('best');32var best = new Best();33var test10 = best.buildBenchmark('test10', function() {34}, 1000);35test10.run();36var Best = require('best');37var best = new Best();38var test11 = best.buildBenchmark('test11', function() {39}, 1000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPractice = require('./BestPractice');2var bestPractice = new BestPractice();3var benchmark = bestPractice.buildBenchmark('test3.json');4console.log(benchmark);5var BestPractice = require('./BestPractice');6var bestPractice = new BestPractice();7var benchmark = bestPractice.buildBenchmark('{"name": "test3", "version": "1.0.0", "description": "test3", "author": "test3", "homepage": "test3", "repository": "test3", "keywords": ["test3"]}');8console.log(benchmark);9var BestPractice = require('./BestPractice');10var bestPractice = new BestPractice();11var benchmark = bestPractice.buildBenchmark({name: 'test3', version: '1.0.0', description: 'test3', author: 'test3', homepage: 'test3', repository: 'test3', keywords: ['test3']});12console.log(benchmark);13var BestPractice = require('./BestPractice');14var bestPractice = new BestPractice();15var benchmark = bestPractice.buildBenchmark({name: 'test3', description: 'test3', author: 'test3', homepage: 'test3', repository: 'test3', keywords: ['test3']});16console.log(benchmark);

Full Screen

Using AI Code Generation

copy

Full Screen

1const Benchmark = require('./Best');2Benchmark.buildBenchmark(functionToTest);3function functionToTest(){4}5const Benchmark = require('./Best');6Benchmark.buildBenchmark(functionToTest, 100000);7function functionToTest(){8}9const Benchmark = require('./Best');10Benchmark.buildBenchmark(functionToTest, 100000, 10);11function functionToTest(){12}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful