Skip to content

Commit 50e0afc

Browse files
committed
chore: adjust benchmark logging
1 parent d5b5e58 commit 50e0afc

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

benchmark/filter-vs-intersection.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ import { intersection } from '../dist/index.js'
44
const emailRegex = /^[\w\-\.]+@([\w-]+\.)+[\w-]{2,}$/
55

66
function runIntersection(sampleCount) {
7-
return fc.sample(fc.stringMatching(intersection(/^.{3,10}$/, emailRegex)), sampleCount)
7+
const startTime = performance.now()
8+
fc.sample(fc.stringMatching(intersection(/^.{3,10}$/, emailRegex)), sampleCount)
9+
return performance.now() - startTime
810
}
911

1012
function runFilter(count) {
11-
return fc.sample(fc.stringMatching(emailRegex).filter(
13+
const startTime = performance.now()
14+
fc.sample(fc.stringMatching(emailRegex).filter(
1215
str => 3 <= str.length && str.length <= 10
1316
), count)
17+
return performance.now() - startTime
1418
}
1519

20+
for (const sampleCount of [10,50,100,500,1000,2000]) {
21+
const filterTime = runFilter(sampleCount)
22+
const interTime = runIntersection(sampleCount)
1623

17-
for (const sampleCount of [10,50,100,500,1000,2000/* ,10_000,20_000,50_000,100_000 */]) {
18-
const filterStart = performance.now()
19-
runFilter(sampleCount)
20-
const filterTime = performance.now() - filterStart
24+
console.debug('\nsample count:', sampleCount)
25+
console.debug('time (post-hoc filter) : ', filterTime)
26+
console.debug('time (regex intersection) : ', interTime)
27+
}
2128

22-
const interStart = performance.now()
23-
runIntersection(sampleCount)
24-
const interTime = performance.now() - interStart
29+
for (const sampleCount of [10_000,20_000,50_000,100_000,1_000_000]) {
30+
const interTime = runIntersection(sampleCount)
2531

2632
console.debug('\nsample count:', sampleCount)
27-
console.debug('time (post-hoc filter) : ', filterTime)
2833
console.debug('time (regex intersection) : ', interTime)
2934
}

0 commit comments

Comments
 (0)