Skip to content

Commit 7daecae

Browse files
committed
Add results table to benchmark script
1 parent c8f3956 commit 7daecae

File tree

6 files changed

+69
-4
lines changed

6 files changed

+69
-4
lines changed

benchmarks/benchmarks.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Benchmark from 'benchmark';
2+
import CliTable from 'cli-table';
23

34
import { run as runAutolinkerCurrent } from './autolinker-current/index';
45
import { run as runAutolinker4_1_1 } from './autolinker-4.1.0/index';
@@ -10,7 +11,8 @@ import { run as runAutolinker3_16_2 } from './autolinker-3.16.2/index';
1011
import { run as runAutolinker2_2_2 } from './autolinker-2.2.2/index';
1112
import { run as runAutolinker1_8_3 } from './autolinker-1.8.3/index';
1213
import { run as runLinkifyIt5_0_0 } from './linkify-it-5.0.0/index';
13-
import { run as runLinkifyJs4_2_0 } from './linkify-js-4.2.0/index';
14+
import { run as runLinkifyHtml4_2_0 } from './linkify-html-4.2.0/index';
15+
import { run as runLinkifyString4_2_0 } from './linkify-string-4.2.0/index';
1416

1517
const suite = new Benchmark.Suite();
1618

@@ -26,12 +28,47 @@ suite
2628
.add('[email protected]', runAutolinker2_2_2)
2729
.add('[email protected]', runAutolinker1_8_3)
2830
.add('[email protected]', runLinkifyIt5_0_0)
29-
.add('[email protected]', runLinkifyJs4_2_0)
31+
.add('[email protected]', runLinkifyHtml4_2_0)
32+
.add('[email protected]', runLinkifyString4_2_0)
3033

3134
.on('cycle', (event: Benchmark.Event) => {
3235
console.log(String(event.target));
3336
})
3437
.on('complete', () => {
38+
console.log('-------------------------------------');
39+
40+
const results: Result[] = suite.map((bench: Benchmark) => {
41+
return {
42+
name: bench.name,
43+
ops: bench.hz,
44+
margin: '±' + bench.stats.rme.toFixed(2) + '%',
45+
};
46+
});
47+
results.sort((a, b) => b.ops - a.ops);
48+
49+
const fastest = results[0];
50+
51+
const table = new CliTable({
52+
head: ['Library', 'Ops/sec', 'MOE', 'Compared to Fastest'],
53+
});
54+
results.forEach(result => {
55+
table.push([
56+
result.name,
57+
Benchmark.formatNumber(Math.floor(result.ops)),
58+
result.margin,
59+
result === fastest
60+
? 'Fastest ✅'
61+
: Math.floor((1 - result.ops / fastest.ops) * 100) + '% slower',
62+
]);
63+
});
64+
console.log(table.toString());
65+
3566
console.log('Fastest is: ' + suite.filter('fastest').map('name'));
3667
})
3768
.run({ async: true, minSamples: 100 });
69+
70+
interface Result {
71+
name: string;
72+
ops: number; // operations per second
73+
margin: string;
74+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://linkify.js.org/docs/linkify-string.html
2+
3+
import linkifyString from 'linkify-string';
4+
import { inputText } from '../input-text';
5+
6+
export function run() {
7+
linkifyString(inputText);
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"linkify-string": "4.2.0"
4+
}
5+
}

pnpm-lock.yaml

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)