@@ -4,26 +4,31 @@ import { intersection } from '../dist/index.js'
4
4
const emailRegex = / ^ [ \w \- \. ] + @ ( [ \w - ] + \. ) + [ \w - ] { 2 , } $ /
5
5
6
6
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
8
10
}
9
11
10
12
function runFilter ( count ) {
11
- return fc . sample ( fc . stringMatching ( emailRegex ) . filter (
13
+ const startTime = performance . now ( )
14
+ fc . sample ( fc . stringMatching ( emailRegex ) . filter (
12
15
str => 3 <= str . length && str . length <= 10
13
16
) , count )
17
+ return performance . now ( ) - startTime
14
18
}
15
19
20
+ for ( const sampleCount of [ 10 , 50 , 100 , 500 , 1000 , 2000 ] ) {
21
+ const filterTime = runFilter ( sampleCount )
22
+ const interTime = runIntersection ( sampleCount )
16
23
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
+ }
21
28
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 )
25
31
26
32
console . debug ( '\nsample count:' , sampleCount )
27
- console . debug ( 'time (post-hoc filter) : ' , filterTime )
28
33
console . debug ( 'time (regex intersection) : ' , interTime )
29
34
}
0 commit comments