Skip to content

Commit 3f25aa9

Browse files
committed
Lift nested functions to top level in parse-matches.ts and use context object to pass state between for better JIT compilation. About a 10% improvement in unit test time
1 parent 7daecae commit 3f25aa9

File tree

2 files changed

+946
-717
lines changed

2 files changed

+946
-717
lines changed

benchmarks/benchmarks.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { run as runAutolinker4_1_1 } from './autolinker-4.1.0/index';
77
// import { run as runAutolinker4_0_2 } from './autolinker-4.0.2/index';
88
// import { run as runAutolinker4_0_1 } from './autolinker-4.0.1/index';
99
// import { run as runAutolinker4_0_0 } from './autolinker-4.0.0/index';
10-
import { run as runAutolinker3_16_2 } from './autolinker-3.16.2/index';
11-
import { run as runAutolinker2_2_2 } from './autolinker-2.2.2/index';
12-
import { run as runAutolinker1_8_3 } from './autolinker-1.8.3/index';
10+
// import { run as runAutolinker3_16_2 } from './autolinker-3.16.2/index';
11+
// import { run as runAutolinker2_2_2 } from './autolinker-2.2.2/index';
12+
// import { run as runAutolinker1_8_3 } from './autolinker-1.8.3/index';
1313
import { run as runLinkifyIt5_0_0 } from './linkify-it-5.0.0/index';
1414
import { run as runLinkifyHtml4_2_0 } from './linkify-html-4.2.0/index';
1515
import { run as runLinkifyString4_2_0 } from './linkify-string-4.2.0/index';
@@ -24,9 +24,9 @@ suite
2424
// .add('[email protected]', runAutolinker4_0_2)
2525
// .add('[email protected]', runAutolinker4_0_1)
2626
// .add('[email protected]', runAutolinker4_0_0)
27-
.add('[email protected]', runAutolinker3_16_2)
28-
.add('[email protected]', runAutolinker2_2_2)
29-
.add('[email protected]', runAutolinker1_8_3)
27+
// .add('[email protected]', runAutolinker3_16_2)
28+
// .add('[email protected]', runAutolinker2_2_2)
29+
// .add('[email protected]', runAutolinker1_8_3)
3030
.add('[email protected]', runLinkifyIt5_0_0)
3131
.add('[email protected]', runLinkifyHtml4_2_0)
3232
.add('[email protected]', runLinkifyString4_2_0)
@@ -52,13 +52,16 @@ suite
5252
head: ['Library', 'Ops/sec', 'MOE', 'Compared to Fastest'],
5353
});
5454
results.forEach(result => {
55+
const resultPctSlower = pctSlower(result.ops, fastest.ops);
56+
const resultTimesSlower = timesSlower(result.ops, fastest.ops);
57+
5558
table.push([
5659
result.name,
5760
Benchmark.formatNumber(Math.floor(result.ops)),
5861
result.margin,
5962
result === fastest
6063
? 'Fastest ✅'
61-
: Math.floor((1 - result.ops / fastest.ops) * 100) + '% slower',
64+
: `${resultPctSlower}% (${resultTimesSlower}x) slower`,
6265
]);
6366
});
6467
console.log(table.toString());
@@ -67,6 +70,14 @@ suite
6770
})
6871
.run({ async: true, minSamples: 100 });
6972

73+
function pctSlower(currentOpsSec: number, fastestOpsSec: number) {
74+
return Math.floor((1 - currentOpsSec / fastestOpsSec) * 100);
75+
}
76+
77+
function timesSlower(currentOpsSec: number, fastestOpsSec: number) {
78+
return (fastestOpsSec / currentOpsSec).toFixed(2);
79+
}
80+
7081
interface Result {
7182
name: string;
7283
ops: number; // operations per second

0 commit comments

Comments
 (0)