3 <script src=
"../htmlrunner.js"></script>
5 window
.onload = function(){ startTest("dromaeo-object-regexp", '812dde38');
7 // Try to force real results
8 var str
= [], tmp
, ret
, re
, testStrings
= [];
11 function randomChar(){
12 return String
.fromCharCode( (25 * Math
.random()) + 97 );
15 for ( var i
= 0; i
< 16384; i
++ )
16 str
.push( randomChar() );
22 function generateTestStrings(count
){
24 if ( testStrings
.length
>= count
)
25 return testStrings
.slice(0, count
);
26 for ( var i
= testStrings
.length
; i
< count
; i
++ ) {
27 // Make all tested strings different
28 t
= randomChar() + str
+ randomChar();
29 nest
= Math
.floor(4 * Math
.random());
30 for ( var j
= 0; j
< nest
; j
++ ) {
31 t
= randomChar() + t
+ randomChar();
33 // Try to minimize benchmark order dependencies by
34 // exercising the strings
35 for ( var j
= 0; j
< t
.length
; j
+= 100 ) {
37 ret
= t
.substring(j
, j
+ 100);
47 // It's impossible to specify empty regexp by simply
48 // using two slashes as this will be interpreted as a
49 // comment start. See note to ECMA-262 5th 7.8.5.
51 tmp
= generateTestStrings(30);
54 test( "Compiled Object Empty Split", function(){
55 for ( var i
= 0; i
< 30; i
++ )
56 ret
= tmp
[i
].split( re
);
61 tmp
= generateTestStrings(30);
64 test( "Compiled Object Char Split", function(){
65 for ( var i
= 0; i
< 30; i
++ )
66 ret
= tmp
[i
].split( re
);
71 tmp
= generateTestStrings(100);
74 test( "Compiled Object Variable Split", function(){
75 for ( var i
= 0; i
< 100; i
++ )
76 ret
= tmp
[i
].split( re
);
79 // TESTS: Compiled RegExps
83 tmp
= generateTestStrings(100);
86 test( "Compiled Match", function(){
87 for ( var i
= 0; i
< 100; i
++ )
88 ret
= tmp
[i
].match( re
);
92 tmp
= generateTestStrings(100);
95 test( "Compiled Test", function(){
96 for ( var i
= 0; i
< 100; i
++ )
97 ret
= re
.test( tmp
[i
] );
101 tmp
= generateTestStrings(100);
104 test( "Compiled Empty Replace", function(){
105 for ( var i
= 0; i
< 50; i
++ )
106 ret
= tmp
[i
].replace( re
, "" );
110 tmp
= generateTestStrings(50);
113 test( "Compiled 12 Char Replace", function(){
114 for ( var i
= 0; i
< 50; i
++ )
115 ret
= tmp
[i
].replace( re
, "asdfasdfasdf" );
119 re
= new RegExp("aaaaaaaaaa", "g");
120 tmp
= generateTestStrings(100);
123 test( "Compiled Object Match", function(){
124 for ( var i
= 0; i
< 100; i
++ )
125 ret
= tmp
[i
].match( re
);
129 tmp
= generateTestStrings(100);
132 test( "Compiled Object Test", function(){
133 for ( var i
= 0; i
< 100; i
++ )
134 ret
= re
.test( tmp
[i
] );
138 tmp
= generateTestStrings(50);
141 test( "Compiled Object Empty Replace", function(){
142 for ( var i
= 0; i
< 50; i
++ )
143 ret
= tmp
[i
].replace( re
, "" );
147 tmp
= generateTestStrings(50);
150 test( "Compiled Object 12 Char Replace", function(){
151 for ( var i
= 0; i
< 50; i
++ )
152 ret
= tmp
[i
].replace( re
, "asdfasdfasdf" );
156 tmp
= generateTestStrings(50);
159 test( "Compiled Object 12 Char Replace Function", function(){
160 for ( var i
= 0; i
< 50; i
++ )
161 ret
= tmp
[i
].replace( re
, function(all
){
162 return "asdfasdfasdf";
166 // TESTS: Variable Length
170 tmp
= generateTestStrings(100);
173 test( "Compiled Variable Match", function(){
174 for ( var i
= 0; i
< 100; i
++ )
175 ret
= tmp
[i
].match( re
);
179 tmp
= generateTestStrings(100);
182 test( "Compiled Variable Test", function(){
183 for ( var i
= 0; i
< 100; i
++ )
184 ret
= re
.test( tmp
[i
] );
188 tmp
= generateTestStrings(50);
191 test( "Compiled Variable Empty Replace", function(){
192 for ( var i
= 0; i
< 50; i
++ )
193 ret
= tmp
[i
].replace( re
, "" );
197 tmp
= generateTestStrings(50);
200 test( "Compiled Variable 12 Char Replace", function(){
201 for ( var i
= 0; i
< 50; i
++ )
202 ret
= tmp
[i
].replace( re
, "asdfasdfasdf" );
206 re
= new RegExp("aaaaaaaaaa", "g");
207 tmp
= generateTestStrings(100);
210 test( "Compiled Variable Object Match", function(){
211 for ( var i
= 0; i
< 100; i
++ )
212 ret
= tmp
[i
].match( re
);
216 tmp
= generateTestStrings(100);
219 test( "Compiled Variable Object Test", function(){
220 for ( var i
= 0; i
< 100; i
++ )
221 ret
= re
.test( tmp
[i
] );
225 tmp
= generateTestStrings(50);
228 test( "Compiled Variable Object Empty Replace", function(){
229 for ( var i
= 0; i
< 50; i
++ )
230 ret
= tmp
[i
].replace( re
, "" );
234 tmp
= generateTestStrings(50);
237 test( "Compiled Variable Object 12 Char Replace", function(){
238 for ( var i
= 0; i
< 50; i
++ )
239 ret
= tmp
[i
].replace( re
, "asdfasdfasdf" );
243 tmp
= generateTestStrings(50);
246 test( "Compiled Variable Object 12 Char Replace Function", function(){
247 for ( var i
= 0; i
< 50; i
++ )
248 ret
= tmp
[i
].replace( re
, function(all
){
249 return "asdfasdfasdf";
257 tmp
= generateTestStrings(100);
260 test( "Compiled Capture Match", function(){
261 for ( var i
= 0; i
< 100; i
++ )
262 ret
= tmp
[i
].match( re
);
266 tmp
= generateTestStrings(50);
269 test( "Compiled Capture Replace", function(){
270 for ( var i
= 0; i
< 50; i
++ )
271 ret
= tmp
[i
].replace( re
, "asdfasdfasdf" );
275 tmp
= generateTestStrings(50);
278 test( "Compiled Capture Replace with Capture", function(){
279 for ( var i
= 0; i
< 50; i
++ )
280 ret
= tmp
[i
].replace( re
, "asdf\\1asdfasdf" );
284 tmp
= generateTestStrings(50);
287 test( "Compiled Capture Replace with Capture Function", function(){
288 for ( var i
= 0; i
< 50; i
++ )
289 ret
= tmp
[i
].replace( re
, function(all
,capture
){
290 return "asdf" + capture
+ "asdfasdf";
295 tmp
= generateTestStrings(50);
298 test( "Compiled Capture Replace with Upperase Capture Function", function(){
299 for ( var i
= 0; i
< 50; i
++ )
300 ret
= tmp
[i
].replace( re
, function(all
,capture
){
301 return capture
.toUpperCase();
305 // TESTS: Uncompiled RegExps
308 tmp
= generateTestStrings(100);
311 test( "Uncompiled Match", function(){
312 for ( var i
= 0; i
< 100; i
++ )
313 ret
= tmp
[i
].match( /aaaaaaaaaa/g );
317 tmp
= generateTestStrings(100);
320 test( "Uncompiled Test", function(){
321 for ( var i
= 0; i
< 100; i
++ )
322 ret
= (/aaaaaaaaaa/g).test( tmp
[i
] );
326 tmp
= generateTestStrings(50);
329 test( "Uncompiled Empty Replace", function(){
330 for ( var i
= 0; i
< 50; i
++ )
331 ret
= tmp
[i
].replace( /aaaaaaaaaa/g, "" );
335 tmp
= generateTestStrings(50);
338 test( "Uncompiled 12 Char Replace", function(){
339 for ( var i
= 0; i
< 50; i
++ )
340 ret
= tmp
[i
].replace( /aaaaaaaaaa/g, "asdfasdfasdf" );
344 tmp
= generateTestStrings(100);
347 test( "Uncompiled Object Match", function(){
348 for ( var i
= 0; i
< 100; i
++ )
349 ret
= tmp
[i
].match( new RegExp("aaaaaaaaaa", "g") );
353 tmp
= generateTestStrings(100);
356 test( "Uncompiled Object Test", function(){
357 for ( var i
= 0; i
< 100; i
++ )
358 ret
= (new RegExp("aaaaaaaaaa", "g")).test( tmp
[i
] );
362 tmp
= generateTestStrings(50);
365 test( "Uncompiled Object Empty Replace", function(){
366 for ( var i
= 0; i
< 50; i
++ )
367 ret
= tmp
[i
].replace( new RegExp("aaaaaaaaaa", "g"), "" );
371 tmp
= generateTestStrings(50);
374 test( "Uncompiled Object 12 Char Replace", function(){
375 for ( var i
= 0; i
< 50; i
++ )
376 ret
= tmp
[i
].replace( new RegExp("aaaaaaaaaa", "g"), "asdfasdfasdf" );