dromaeo-object-regexp.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. startTest("dromaeo-object-regexp", '812dde38');
  2. // Try to force real results
  3. var str = [], tmp, ret, re, testStrings = [];
  4. var i = 65536;
  5. function randomChar() {
  6. return String.fromCharCode((25 * Math.random()) + 97);
  7. }
  8. for (var i = 0; i < 16384; i++)
  9. str.push(randomChar());
  10. str = str.join("");
  11. str += str;
  12. str += str;
  13. function generateTestStrings(count) {
  14. var t, nest;
  15. if (testStrings.length >= count)
  16. return testStrings.slice(0, count);
  17. for (var i = testStrings.length; i < count; i++) {
  18. // Make all tested strings different
  19. t = randomChar() + str + randomChar();
  20. nest = Math.floor(4 * Math.random());
  21. for (var j = 0; j < nest; j++) {
  22. t = randomChar() + t + randomChar();
  23. }
  24. // Try to minimize benchmark order dependencies by
  25. // exercising the strings
  26. for (var j = 0; j < t.length; j += 100) {
  27. ret = t[j];
  28. ret = t.substring(j, j + 100);
  29. }
  30. testStrings[i] = t;
  31. }
  32. return testStrings;
  33. }
  34. // TESTS: split
  35. prep(function () {
  36. // It's impossible to specify empty regexp by simply
  37. // using two slashes as this will be interpreted as a
  38. // comment start. See note to ECMA-262 5th 7.8.5.
  39. re = /(?:)/;
  40. tmp = generateTestStrings(30);
  41. });
  42. test("Compiled Object Empty Split", function () {
  43. for (var i = 0; i < 30; i++)
  44. ret = tmp[i].split(re);
  45. });
  46. prep(function () {
  47. re = /a/;
  48. tmp = generateTestStrings(30);
  49. });
  50. test("Compiled Object Char Split", function () {
  51. for (var i = 0; i < 30; i++)
  52. ret = tmp[i].split(re);
  53. });
  54. prep(function () {
  55. re = /.*/;
  56. tmp = generateTestStrings(100);
  57. });
  58. test("Compiled Object Variable Split", function () {
  59. for (var i = 0; i < 100; i++)
  60. ret = tmp[i].split(re);
  61. });
  62. // TESTS: Compiled RegExps
  63. prep(function () {
  64. re = /aaaaaaaaaa/g;
  65. tmp = generateTestStrings(100);
  66. });
  67. test("Compiled Match", function () {
  68. for (var i = 0; i < 100; i++)
  69. ret = tmp[i].match(re);
  70. });
  71. prep(function () {
  72. tmp = generateTestStrings(100);
  73. });
  74. test("Compiled Test", function () {
  75. for (var i = 0; i < 100; i++)
  76. ret = re.test(tmp[i]);
  77. });
  78. prep(function () {
  79. tmp = generateTestStrings(100);
  80. });
  81. test("Compiled Empty Replace", function () {
  82. for (var i = 0; i < 50; i++)
  83. ret = tmp[i].replace(re, "");
  84. });
  85. prep(function () {
  86. tmp = generateTestStrings(50);
  87. });
  88. test("Compiled 12 Char Replace", function () {
  89. for (var i = 0; i < 50; i++)
  90. ret = tmp[i].replace(re, "asdfasdfasdf");
  91. });
  92. prep(function () {
  93. re = new RegExp("aaaaaaaaaa", "g");
  94. tmp = generateTestStrings(100);
  95. });
  96. test("Compiled Object Match", function () {
  97. for (var i = 0; i < 100; i++)
  98. ret = tmp[i].match(re);
  99. });
  100. prep(function () {
  101. tmp = generateTestStrings(100);
  102. });
  103. test("Compiled Object Test", function () {
  104. for (var i = 0; i < 100; i++)
  105. ret = re.test(tmp[i]);
  106. });
  107. prep(function () {
  108. tmp = generateTestStrings(50);
  109. });
  110. test("Compiled Object Empty Replace", function () {
  111. for (var i = 0; i < 50; i++)
  112. ret = tmp[i].replace(re, "");
  113. });
  114. prep(function () {
  115. tmp = generateTestStrings(50);
  116. });
  117. test("Compiled Object 12 Char Replace", function () {
  118. for (var i = 0; i < 50; i++)
  119. ret = tmp[i].replace(re, "asdfasdfasdf");
  120. });
  121. prep(function () {
  122. tmp = generateTestStrings(50);
  123. });
  124. test("Compiled Object 12 Char Replace Function", function () {
  125. for (var i = 0; i < 50; i++)
  126. ret = tmp[i].replace(re, function (all) {
  127. return "asdfasdfasdf";
  128. });
  129. });
  130. // TESTS: Variable Length
  131. prep(function () {
  132. re = /a.*a/;
  133. tmp = generateTestStrings(100);
  134. });
  135. test("Compiled Variable Match", function () {
  136. for (var i = 0; i < 100; i++)
  137. ret = tmp[i].match(re);
  138. });
  139. prep(function () {
  140. tmp = generateTestStrings(100);
  141. });
  142. test("Compiled Variable Test", function () {
  143. for (var i = 0; i < 100; i++)
  144. ret = re.test(tmp[i]);
  145. });
  146. prep(function () {
  147. tmp = generateTestStrings(50);
  148. });
  149. test("Compiled Variable Empty Replace", function () {
  150. for (var i = 0; i < 50; i++)
  151. ret = tmp[i].replace(re, "");
  152. });
  153. prep(function () {
  154. tmp = generateTestStrings(50);
  155. });
  156. test("Compiled Variable 12 Char Replace", function () {
  157. for (var i = 0; i < 50; i++)
  158. ret = tmp[i].replace(re, "asdfasdfasdf");
  159. });
  160. prep(function () {
  161. re = new RegExp("aaaaaaaaaa", "g");
  162. tmp = generateTestStrings(100);
  163. });
  164. test("Compiled Variable Object Match", function () {
  165. for (var i = 0; i < 100; i++)
  166. ret = tmp[i].match(re);
  167. });
  168. prep(function () {
  169. tmp = generateTestStrings(100);
  170. });
  171. test("Compiled Variable Object Test", function () {
  172. for (var i = 0; i < 100; i++)
  173. ret = re.test(tmp[i]);
  174. });
  175. prep(function () {
  176. tmp = generateTestStrings(50);
  177. });
  178. test("Compiled Variable Object Empty Replace", function () {
  179. for (var i = 0; i < 50; i++)
  180. ret = tmp[i].replace(re, "");
  181. });
  182. prep(function () {
  183. tmp = generateTestStrings(50);
  184. });
  185. test("Compiled Variable Object 12 Char Replace", function () {
  186. for (var i = 0; i < 50; i++)
  187. ret = tmp[i].replace(re, "asdfasdfasdf");
  188. });
  189. prep(function () {
  190. tmp = generateTestStrings(50);
  191. });
  192. test("Compiled Variable Object 12 Char Replace Function", function () {
  193. for (var i = 0; i < 50; i++)
  194. ret = tmp[i].replace(re, function (all) {
  195. return "asdfasdfasdf";
  196. });
  197. });
  198. // TESTS: Capturing
  199. prep(function () {
  200. re = /aa(b)aa/g;
  201. tmp = generateTestStrings(100);
  202. });
  203. test("Compiled Capture Match", function () {
  204. for (var i = 0; i < 100; i++)
  205. ret = tmp[i].match(re);
  206. });
  207. prep(function () {
  208. tmp = generateTestStrings(50);
  209. });
  210. test("Compiled Capture Replace", function () {
  211. for (var i = 0; i < 50; i++)
  212. ret = tmp[i].replace(re, "asdfasdfasdf");
  213. });
  214. prep(function () {
  215. tmp = generateTestStrings(50);
  216. });
  217. test("Compiled Capture Replace with Capture", function () {
  218. for (var i = 0; i < 50; i++)
  219. ret = tmp[i].replace(re, "asdf\\1asdfasdf");
  220. });
  221. prep(function () {
  222. tmp = generateTestStrings(50);
  223. });
  224. test("Compiled Capture Replace with Capture Function", function () {
  225. for (var i = 0; i < 50; i++)
  226. ret = tmp[i].replace(re, function (all, capture) {
  227. return "asdf" + capture + "asdfasdf";
  228. });
  229. });
  230. prep(function () {
  231. tmp = generateTestStrings(50);
  232. });
  233. test("Compiled Capture Replace with Upperase Capture Function", function () {
  234. for (var i = 0; i < 50; i++)
  235. ret = tmp[i].replace(re, function (all, capture) {
  236. return capture.toUpperCase();
  237. });
  238. });
  239. // TESTS: Uncompiled RegExps
  240. prep(function () {
  241. tmp = generateTestStrings(100);
  242. });
  243. test("Uncompiled Match", function () {
  244. for (var i = 0; i < 100; i++)
  245. ret = tmp[i].match(/aaaaaaaaaa/g);
  246. });
  247. prep(function () {
  248. tmp = generateTestStrings(100);
  249. });
  250. test("Uncompiled Test", function () {
  251. for (var i = 0; i < 100; i++)
  252. ret = (/aaaaaaaaaa/g).test(tmp[i]);
  253. });
  254. prep(function () {
  255. tmp = generateTestStrings(50);
  256. });
  257. test("Uncompiled Empty Replace", function () {
  258. for (var i = 0; i < 50; i++)
  259. ret = tmp[i].replace(/aaaaaaaaaa/g, "");
  260. });
  261. prep(function () {
  262. tmp = generateTestStrings(50);
  263. });
  264. test("Uncompiled 12 Char Replace", function () {
  265. for (var i = 0; i < 50; i++)
  266. ret = tmp[i].replace(/aaaaaaaaaa/g, "asdfasdfasdf");
  267. });
  268. prep(function () {
  269. tmp = generateTestStrings(100);
  270. });
  271. test("Uncompiled Object Match", function () {
  272. for (var i = 0; i < 100; i++)
  273. ret = tmp[i].match(new RegExp("aaaaaaaaaa", "g"));
  274. });
  275. prep(function () {
  276. tmp = generateTestStrings(100);
  277. });
  278. test("Uncompiled Object Test", function () {
  279. for (var i = 0; i < 100; i++)
  280. ret = (new RegExp("aaaaaaaaaa", "g")).test(tmp[i]);
  281. });
  282. prep(function () {
  283. tmp = generateTestStrings(50);
  284. });
  285. test("Uncompiled Object Empty Replace", function () {
  286. for (var i = 0; i < 50; i++)
  287. ret = tmp[i].replace(new RegExp("aaaaaaaaaa", "g"), "");
  288. });
  289. prep(function () {
  290. tmp = generateTestStrings(50);
  291. });
  292. test("Uncompiled Object 12 Char Replace", function () {
  293. for (var i = 0; i < 50; i++)
  294. ret = tmp[i].replace(new RegExp("aaaaaaaaaa", "g"), "asdfasdfasdf");
  295. });
  296. endTest();