@@ -3,33 +3,43 @@ import { RB } from '../dist/index.js'
3
3
4
4
const emailRegex = / ^ [ \w \- \. ] + @ ( [ \w - ] + \. ) + [ \w - ] { 2 , } $ /
5
5
6
- function runIntersection ( sampleCount ) {
6
+ function runIntersection ( sampleCount : number ) {
7
7
const startTime = performance . now ( )
8
8
const intersection = RB ( emailRegex ) . and ( / ^ .{ 3 , 10 } $ / ) . toRegExp ( )
9
9
fc . sample ( fc . stringMatching ( intersection ) , sampleCount )
10
10
return performance . now ( ) - startTime
11
11
}
12
12
13
- function runFilter ( count ) {
13
+ function runFilter ( count : number ) {
14
14
const startTime = performance . now ( )
15
15
fc . sample ( fc . stringMatching ( emailRegex ) . filter (
16
16
str => 3 <= str . length && str . length <= 10
17
17
) , count )
18
18
return performance . now ( ) - startTime
19
19
}
20
20
21
+ function runOwnSample ( sampleCount : number ) {
22
+ const startTime = performance . now ( )
23
+ RB ( emailRegex ) . and ( / ^ .{ 3 , 10 } $ / ) . sample ( ) . take ( sampleCount ) . toArray ( )
24
+ return performance . now ( ) - startTime
25
+ }
26
+
21
27
for ( const sampleCount of [ 10 , 50 , 100 , 500 , 1000 , 2000 ] ) {
22
28
const filterTime = runFilter ( sampleCount )
23
29
const interTime = runIntersection ( sampleCount )
30
+ const ownSampleTime = runOwnSample ( sampleCount )
24
31
25
32
console . debug ( '\nsample count:' , sampleCount )
26
33
console . debug ( 'time (post-hoc filter) : ' , filterTime )
27
34
console . debug ( 'time (regex intersection) : ' , interTime )
35
+ console . debug ( 'time (own sample) : ' , ownSampleTime )
28
36
}
29
37
30
- for ( const sampleCount of [ 10_000 , 20_000 , 50_000 , 100_000 , 1_000_000 ] ) {
38
+ for ( const sampleCount of [ 10_000 , 20_000 , 50_000 , 100_000 , 1_000_000 , 2_000_000 , 5_000_000 ] ) {
31
39
const interTime = runIntersection ( sampleCount )
40
+ const ownSampleTime = runOwnSample ( sampleCount )
32
41
33
42
console . debug ( '\nsample count:' , sampleCount )
34
43
console . debug ( 'time (regex intersection) : ' , interTime )
44
+ console . debug ( 'time (own sample) : ' , ownSampleTime )
35
45
}
0 commit comments