Skip to content

Commit 388eeed

Browse files
committed
Add builtin benchmarks
1 parent 122631a commit 388eeed

File tree

1 file changed

+56
-0
lines changed
  • lib/node_modules/@stdlib/string/base/replace/benchmark

1 file changed

+56
-0
lines changed

lib/node_modules/@stdlib/string/base/replace/benchmark/benchmark.js

+56
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,59 @@ bench( pkg+'::replacer', function benchmark( b ) {
8383
return '/' + p1 + '/';
8484
}
8585
});
86+
87+
bench( pkg+'::builtin,regexp', function benchmark( b ) {
88+
var values;
89+
var out;
90+
var str;
91+
var re;
92+
var i;
93+
94+
values = [
95+
'abc',
96+
'def',
97+
'hig'
98+
];
99+
str = 'To be, or not to be, that is the question.';
100+
re = /be/g;
101+
102+
b.tic();
103+
for ( i = 0; i < b.iterations; i++ ) {
104+
out = str.replace( re, values[ i%values.length ] );
105+
if ( typeof out !== 'string' ) {
106+
b.fail( 'should return a string' );
107+
}
108+
}
109+
b.toc();
110+
if ( !isString( out ) ) {
111+
b.fail( 'should return a string' );
112+
}
113+
b.pass( 'benchmark finished' );
114+
b.end();
115+
});
116+
117+
bench( pkg+'::builtin,replacer', function benchmark( b ) {
118+
var out;
119+
var str;
120+
var i;
121+
122+
str = 'To be, or not to be, that is the question.';
123+
124+
b.tic();
125+
for ( i = 0; i < b.iterations; i++ ) {
126+
out = str.replace( 'be', replacer );
127+
if ( typeof out !== 'string' ) {
128+
b.fail( 'should return a string' );
129+
}
130+
}
131+
b.toc();
132+
if ( !isString( out ) ) {
133+
b.fail( 'should return a string' );
134+
}
135+
b.pass( 'benchmark finished' );
136+
b.end();
137+
138+
function replacer( match, p1 ) {
139+
return '/' + p1 + '/';
140+
}
141+
});

0 commit comments

Comments
 (0)