OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../htmlrunner.js"></script> |
| 4 <script> |
| 5 window.onload = function(){ startTest("dromaeo-object-regexp", ''); |
| 6 |
| 7 // Try to force real results |
| 8 var str = [], tmp, ret, re; |
| 9 var i = 65536; |
| 10 |
| 11 for ( var i = 0; i < 16384; i++ ) |
| 12 str.push( String.fromCharCode( (25 * Math.random()) + 97 ) ); |
| 13 |
| 14 str = str.join(""); |
| 15 str += str; |
| 16 str += str; |
| 17 |
| 18 // TESTS: split |
| 19 |
| 20 prep(function(){ |
| 21 re = //; |
| 22 tmp = str; |
| 23 }); |
| 24 |
| 25 test( "Compiled Object Empty Split", function(){ |
| 26 for ( var i = 0; i < 100; i++ ) |
| 27 ret = tmp.split( re ); |
| 28 }); |
| 29 |
| 30 prep(function(){ |
| 31 re = /a/; |
| 32 tmp = str; |
| 33 }); |
| 34 |
| 35 test( "Compiled Object Char Split", function(){ |
| 36 for ( var i = 0; i < 30; i++ ) |
| 37 ret = tmp.split( re ); |
| 38 }); |
| 39 |
| 40 prep(function(){ |
| 41 re = /.*/; |
| 42 tmp = str; |
| 43 }); |
| 44 |
| 45 test( "Compiled Object Variable Split", function(){ |
| 46 for ( var i = 0; i < 100; i++ ) |
| 47 ret = tmp.split( re ); |
| 48 }); |
| 49 |
| 50 // TESTS: Compiled RegExps |
| 51 |
| 52 prep(function(){ |
| 53 re = /aaaaaaaaaa/g; |
| 54 tmp = str; |
| 55 }); |
| 56 |
| 57 test( "Compiled Match", function(){ |
| 58 for ( var i = 0; i < 100; i++ ) |
| 59 ret = tmp.match( re ); |
| 60 }); |
| 61 |
| 62 prep(function(){ |
| 63 tmp = str; |
| 64 }); |
| 65 |
| 66 test( "Compiled Test", function(){ |
| 67 for ( var i = 0; i < 100; i++ ) |
| 68 ret = re.test( tmp ); |
| 69 }); |
| 70 |
| 71 prep(function(){ |
| 72 tmp = str; |
| 73 }); |
| 74 |
| 75 test( "Compiled Empty Replace", function(){ |
| 76 for ( var i = 0; i < 50; i++ ) |
| 77 ret = tmp.replace( re, "" ); |
| 78 }); |
| 79 |
| 80 prep(function(){ |
| 81 tmp = str; |
| 82 }); |
| 83 |
| 84 test( "Compiled 12 Char Replace", function(){ |
| 85 for ( var i = 0; i < 50; i++ ) |
| 86 ret = tmp.replace( re, "asdfasdfasdf" ); |
| 87 }); |
| 88 |
| 89 prep(function(){ |
| 90 re = new RegExp("aaaaaaaaaa", "g"); |
| 91 tmp = str; |
| 92 }); |
| 93 |
| 94 test( "Compiled Object Match", function(){ |
| 95 for ( var i = 0; i < 100; i++ ) |
| 96 ret = tmp.match( re ); |
| 97 }); |
| 98 |
| 99 prep(function(){ |
| 100 tmp = str; |
| 101 }); |
| 102 |
| 103 test( "Compiled Object Test", function(){ |
| 104 for ( var i = 0; i < 100; i++ ) |
| 105 ret = re.test( tmp ); |
| 106 }); |
| 107 |
| 108 prep(function(){ |
| 109 tmp = str; |
| 110 }); |
| 111 |
| 112 test( "Compiled Object Empty Replace", function(){ |
| 113 for ( var i = 0; i < 50; i++ ) |
| 114 ret = tmp.replace( re, "" ); |
| 115 }); |
| 116 |
| 117 prep(function(){ |
| 118 tmp = str; |
| 119 }); |
| 120 |
| 121 test( "Compiled Object 12 Char Replace", function(){ |
| 122 for ( var i = 0; i < 50; i++ ) |
| 123 ret = tmp.replace( re, "asdfasdfasdf" ); |
| 124 }); |
| 125 |
| 126 prep(function(){ |
| 127 tmp = str; |
| 128 }); |
| 129 |
| 130 test( "Compiled Object 12 Char Replace Function", function(){ |
| 131 for ( var i = 0; i < 50; i++ ) |
| 132 ret = tmp.replace( re, function(all){ |
| 133 return "asdfasdfasdf"; |
| 134 }); |
| 135 }); |
| 136 |
| 137 // TESTS: Variable Length |
| 138 |
| 139 prep(function(){ |
| 140 re = /a.*a/; |
| 141 tmp = str; |
| 142 }); |
| 143 |
| 144 test( "Compiled Variable Match", function(){ |
| 145 for ( var i = 0; i < 100; i++ ) |
| 146 ret = tmp.match( re ); |
| 147 }); |
| 148 |
| 149 prep(function(){ |
| 150 tmp = str; |
| 151 }); |
| 152 |
| 153 test( "Compiled Variable Test", function(){ |
| 154 for ( var i = 0; i < 100; i++ ) |
| 155 ret = re.test( tmp ); |
| 156 }); |
| 157 |
| 158 prep(function(){ |
| 159 tmp = str; |
| 160 }); |
| 161 |
| 162 test( "Compiled Variable Empty Replace", function(){ |
| 163 for ( var i = 0; i < 50; i++ ) |
| 164 ret = tmp.replace( re, "" ); |
| 165 }); |
| 166 |
| 167 prep(function(){ |
| 168 tmp = str; |
| 169 }); |
| 170 |
| 171 test( "Compiled Variable 12 Char Replace", function(){ |
| 172 for ( var i = 0; i < 50; i++ ) |
| 173 ret = tmp.replace( re, "asdfasdfasdf" ); |
| 174 }); |
| 175 |
| 176 prep(function(){ |
| 177 re = new RegExp("aaaaaaaaaa", "g"); |
| 178 tmp = str; |
| 179 }); |
| 180 |
| 181 test( "Compiled Variable Object Match", function(){ |
| 182 for ( var i = 0; i < 100; i++ ) |
| 183 ret = tmp.match( re ); |
| 184 }); |
| 185 |
| 186 prep(function(){ |
| 187 tmp = str; |
| 188 }); |
| 189 |
| 190 test( "Compiled Variable Object Test", function(){ |
| 191 for ( var i = 0; i < 100; i++ ) |
| 192 ret = re.test( tmp ); |
| 193 }); |
| 194 |
| 195 prep(function(){ |
| 196 tmp = str; |
| 197 }); |
| 198 |
| 199 test( "Compiled Variable Object Empty Replace", function(){ |
| 200 for ( var i = 0; i < 50; i++ ) |
| 201 ret = tmp.replace( re, "" ); |
| 202 }); |
| 203 |
| 204 prep(function(){ |
| 205 tmp = str; |
| 206 }); |
| 207 |
| 208 test( "Compiled Variable Object 12 Char Replace", function(){ |
| 209 for ( var i = 0; i < 50; i++ ) |
| 210 ret = tmp.replace( re, "asdfasdfasdf" ); |
| 211 }); |
| 212 |
| 213 prep(function(){ |
| 214 tmp = str; |
| 215 }); |
| 216 |
| 217 test( "Compiled Variable Object 12 Char Replace Function", function(){ |
| 218 for ( var i = 0; i < 50; i++ ) |
| 219 ret = tmp.replace( re, function(all){ |
| 220 return "asdfasdfasdf"; |
| 221 }); |
| 222 }); |
| 223 |
| 224 // TESTS: Capturing |
| 225 |
| 226 prep(function(){ |
| 227 re = /aa(b)aa/g; |
| 228 tmp = str; |
| 229 }); |
| 230 |
| 231 test( "Compiled Capture Match", function(){ |
| 232 for ( var i = 0; i < 100; i++ ) |
| 233 ret = tmp.match( re ); |
| 234 }); |
| 235 |
| 236 prep(function(){ |
| 237 tmp = str; |
| 238 }); |
| 239 |
| 240 test( "Compiled Capture Replace", function(){ |
| 241 for ( var i = 0; i < 50; i++ ) |
| 242 ret = tmp.replace( re, "asdfasdfasdf" ); |
| 243 }); |
| 244 |
| 245 prep(function(){ |
| 246 tmp = str; |
| 247 }); |
| 248 |
| 249 test( "Compiled Capture Replace with Capture", function(){ |
| 250 for ( var i = 0; i < 50; i++ ) |
| 251 ret = tmp.replace( re, "asdf\\1asdfasdf" ); |
| 252 }); |
| 253 |
| 254 prep(function(){ |
| 255 tmp = str; |
| 256 }); |
| 257 |
| 258 test( "Compiled Capture Replace with Capture Function", function(){ |
| 259 for ( var i = 0; i < 50; i++ ) |
| 260 ret = tmp.replace( re, function(all,capture){ |
| 261 return "asdf" + capture + "asdfasdf"; |
| 262 }); |
| 263 }); |
| 264 |
| 265 prep(function(){ |
| 266 tmp = str; |
| 267 }); |
| 268 |
| 269 test( "Compiled Capture Replace with Upperase Capture Function", functio
n(){ |
| 270 for ( var i = 0; i < 50; i++ ) |
| 271 ret = tmp.replace( re, function(all,capture){ |
| 272 return capture.toUpperCase(); |
| 273 }); |
| 274 }); |
| 275 |
| 276 // TESTS: Uncompiled RegExps |
| 277 |
| 278 prep(function(){ |
| 279 tmp = str; |
| 280 }); |
| 281 |
| 282 test( "Uncompiled Match", function(){ |
| 283 for ( var i = 0; i < 100; i++ ) |
| 284 ret = tmp.match( /aaaaaaaaaa/g ); |
| 285 }); |
| 286 |
| 287 prep(function(){ |
| 288 tmp = str; |
| 289 }); |
| 290 |
| 291 test( "Uncompiled Test", function(){ |
| 292 for ( var i = 0; i < 100; i++ ) |
| 293 ret = (/aaaaaaaaaa/g).test( tmp ); |
| 294 }); |
| 295 |
| 296 prep(function(){ |
| 297 tmp = str; |
| 298 }); |
| 299 |
| 300 test( "Uncompiled Empty Replace", function(){ |
| 301 for ( var i = 0; i < 50; i++ ) |
| 302 ret = tmp.replace( /aaaaaaaaaa/g, "" ); |
| 303 }); |
| 304 |
| 305 prep(function(){ |
| 306 tmp = str; |
| 307 }); |
| 308 |
| 309 test( "Uncompiled 12 Char Replace", function(){ |
| 310 for ( var i = 0; i < 50; i++ ) |
| 311 ret = tmp.replace( /aaaaaaaaaa/g, "asdfasdfasdf" ); |
| 312 }); |
| 313 |
| 314 prep(function(){ |
| 315 tmp = str; |
| 316 }); |
| 317 |
| 318 test( "Uncompiled Object Match", function(){ |
| 319 for ( var i = 0; i < 100; i++ ) |
| 320 ret = tmp.match( new RegExp("aaaaaaaaaa", "g") ); |
| 321 }); |
| 322 |
| 323 prep(function(){ |
| 324 tmp = str; |
| 325 }); |
| 326 |
| 327 test( "Uncompiled Object Test", function(){ |
| 328 for ( var i = 0; i < 100; i++ ) |
| 329 ret = (new RegExp("aaaaaaaaaa", "g")).test( tmp ); |
| 330 }); |
| 331 |
| 332 prep(function(){ |
| 333 tmp = str; |
| 334 }); |
| 335 |
| 336 test( "Uncompiled Object Empty Replace", function(){ |
| 337 for ( var i = 0; i < 50; i++ ) |
| 338 ret = tmp.replace( new RegExp("aaaaaaaaaa", "g"), "" ); |
| 339 }); |
| 340 |
| 341 prep(function(){ |
| 342 tmp = str; |
| 343 }); |
| 344 |
| 345 test( "Uncompiled Object 12 Char Replace", function(){ |
| 346 for ( var i = 0; i < 50; i++ ) |
| 347 ret = tmp.replace( new RegExp("aaaaaaaaaa", "g"), "asdfa
sdfasdf" ); |
| 348 }); |
| 349 |
| 350 endTest(); }; |
| 351 </script> |
| 352 </head> |
| 353 <body></body> |
| 354 </html> |
OLD | NEW |