|
9 | 9 |
|
10 | 10 | 'use strict';
|
11 | 11 |
|
12 |
| -const { Suite } = require('benchmark'); |
| 12 | +const { Benchmark } = require('benchmark'); |
13 | 13 | const { execSync } = require('child_process');
|
14 | 14 | const os = require('os');
|
15 | 15 | const fs = require('fs');
|
@@ -79,33 +79,21 @@ function findFiles(cwd, pattern) {
|
79 | 79 |
|
80 | 80 | // Run a given benchmark test with the provided revisions.
|
81 | 81 | function runBenchmark(benchmark, environments) {
|
82 |
| - const modules = environments.map(({ distPath }) => |
83 |
| - require(path.join(distPath, benchmark)) |
84 |
| - ); |
85 |
| - const benchResults = [] |
86 |
| - |
87 |
| - const suite = new Suite(modules[0].name, { |
88 |
| - onStart(event) { |
89 |
| - console.log('⏱️ ' + event.currentTarget.name); |
90 |
| - }, |
91 |
| - onCycle({ target }) { |
92 |
| - benchResults.push(target); |
93 |
| - process.stdout.write( |
94 |
| - ' ' + cyan(benchResults.length) + ' tests completed.\u000D', |
95 |
| - ); |
96 |
| - }, |
97 |
| - onError(event) { |
98 |
| - console.error(event.target.error); |
99 |
| - }, |
100 |
| - onComplete() { |
101 |
| - console.log('\n'); |
102 |
| - beautifyBenchmark(benchResults); |
103 |
| - }, |
| 82 | + let benchmarkName; |
| 83 | + const benches = environments.map(environment => { |
| 84 | + const module = require(path.join(environment.distPath, benchmark)) |
| 85 | + benchmarkName = module.name; |
| 86 | + return new Benchmark(environment.revision, module.measure); |
104 | 87 | });
|
105 |
| - for (let i = 0; i < environments.length; i++) { |
106 |
| - suite.add(environments[i].revision, modules[i].measure); |
| 88 | + |
| 89 | + console.log('⏱️ ' + benchmarkName); |
| 90 | + for (let i = 0; i < benches.length; ++i) { |
| 91 | + benches[i].run({ async: false }); |
| 92 | + process.stdout.write(' ' + cyan(i + 1) + ' tests completed.\u000D'); |
107 | 93 | }
|
108 |
| - suite.run({ async: false }); |
| 94 | + console.log('\n'); |
| 95 | + |
| 96 | + beautifyBenchmark(benches); |
109 | 97 | console.log('');
|
110 | 98 | }
|
111 | 99 |
|
|
0 commit comments