Skip to content

Commit 9af9b5c

Browse files
committed
Add regular expression benchmark for comparison
1 parent 7f8034a commit 9af9b5c

File tree

1 file changed

+46
-0
lines changed
  • lib/node_modules/@stdlib/assert/is-alphanumeric/benchmark

1 file changed

+46
-0
lines changed

lib/node_modules/@stdlib/assert/is-alphanumeric/benchmark/benchmark.js

+46
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,49 @@ bench( pkg+'::string', function benchmark( b ) {
7070
b.pass( 'benchmark finished' );
7171
b.end();
7272
});
73+
74+
bench( pkg+'::regexp-single-character', function benchmark( b ) {
75+
var bool;
76+
var str;
77+
var RE;
78+
var i;
79+
80+
RE = /[a-zA-Z0-9]+/;
81+
b.tic();
82+
for ( i = 0; i < b.iterations; i++ ) {
83+
str = fromCodePoint( (i%74)+48 );
84+
bool = RE.test( str );
85+
if ( !isBoolean( bool ) ) {
86+
b.fail( 'should return a boolean' );
87+
}
88+
}
89+
b.toc();
90+
if ( !isBoolean( bool ) ) {
91+
b.fail( 'should return a boolean' );
92+
}
93+
b.pass( 'benchmark finished' );
94+
b.end();
95+
});
96+
97+
bench( pkg+'::regexp-string', function benchmark( b ) {
98+
var bool;
99+
var str;
100+
var RE;
101+
var i;
102+
103+
RE = /[a-zA-Z0-9]+/;
104+
b.tic();
105+
for ( i = 0; i < b.iterations; i++ ) {
106+
str = '0123456789' + fromCodePoint( (i%74)+48 );
107+
bool = RE.test( str );
108+
if ( !isBoolean( bool ) ) {
109+
b.fail( 'should return a boolean' );
110+
}
111+
}
112+
b.toc();
113+
if ( !isBoolean( bool ) ) {
114+
b.fail( 'should return a boolean' );
115+
}
116+
b.pass( 'benchmark finished' );
117+
b.end();
118+
});

0 commit comments

Comments
 (0)