gebcnspeedtest.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="./prototype-for-gebcn-test.js"></script>
  4. <script type="text/javascript">
  5. function run(type)
  6. {
  7. var iterations = 10000;
  8. var result;
  9. var i = 0;
  10. var current;
  11. var start;
  12. var body = document.body;
  13. switch(type)
  14. {
  15. case "native":
  16. //test for a working native getElementsByClassName
  17. if(!document.getElementsByClassName)
  18. {
  19. alert("Your browser does not have a native implementation of getElementsByClassName");
  20. return;
  21. }
  22. start = new Date();
  23. for(; iterations > 0; --iterations)
  24. {
  25. result = body.getElementsByClassName("test1 test2 test3 test4");
  26. for(; current = result[i]; i++) {}
  27. }
  28. break;
  29. case "xpath":
  30. start = new Date();
  31. for(; iterations > 0; --iterations)
  32. {
  33. result = document.getXPathElementsByClassName("test1 test2 test3 test4", body);
  34. for(; current = result[i]; i++) {}
  35. }
  36. break;
  37. case "js":
  38. start = new Date();
  39. for(; iterations > 0; --iterations)
  40. {
  41. result = document.getJSElementsByClassName("test1 test2 test3 test4", body);
  42. for(; current = result[i]; i++) {}
  43. }
  44. break;
  45. }
  46. var end = new Date();
  47. document.getElementById("output").innerHTML = end - start;
  48. }
  49. </script>
  50. </head>
  51. <body>
  52. <button onclick="run('native');">run</button>
  53. <button onclick="run('xpath');">runxpath</button>
  54. <button onclick="run('js');">runjs</button>
  55. <span id="output"></span>
  56. <div class="test1 test2 test3 test4">
  57. <div class="test1 test2 test3 test4"></div>
  58. <div class="test1 test2 test3 test4"></div>
  59. <div class="test1 test2 test3 test4"></div>
  60. <div class="test1 test2 test3 test4"></div>
  61. <div class="test1 test2 test3 test4"></div>
  62. <div class="test1 test2 test3 test4"></div>
  63. <div class="test1 test2 test3 test4"></div>
  64. <div class="test1 test2 test3 test4"></div>
  65. <div class="test1 test2 test3 test4"></div>
  66. <div class="test1 test2 test3 test4"></div>
  67. <div class="test1 test2 test3 test4"></div>
  68. <div class="test1 test2 test3 test4"></div>
  69. <div class="test1 test2 test3 test4"></div>
  70. <div class="test1 test2 test3 test4"></div>
  71. <div class="test1 test2 test3 test4"></div>
  72. <div class="test1 test2 test3 test4"></div>
  73. <div class="test1 test2 test3 test4"></div>
  74. <div class="test1 test2 test3 test4"></div>
  75. <div class="test1 test2 test3 test4"></div>
  76. <div class="test1 test2 test3 test4"></div>
  77. <div class="test1 test2 test3 test4"></div>
  78. <div class="test1 test2 test3 test4"></div>
  79. <div class="test1 test2 test3 test4"></div>
  80. <div class="test1 test2 test3 test4"></div>
  81. <div class="test1 test2 test3 test4"></div>
  82. <div class="test1 test2 test3 test4"></div>
  83. <div class="test1 test2 test3 test4"></div>
  84. <div class="test1 test2 test3 test4"></div>
  85. <div class="test1 test2 test3 test4"></div>
  86. <div class="test1 test2 test3 test4"></div>
  87. <div class="test1 test2 test3 test4"></div>
  88. <div class="test1 test2 test3 test4"></div>
  89. <div class="test1 test2 test3 test4"></div>
  90. <div class="test1 test2 test3 test4"></div>
  91. <div class="test1 test2 test3 test4"></div>
  92. <div class="test1 test2 test3 test4"></div>
  93. <div class="test1 test2 test3 test4"></div>
  94. <div class="test1 test2 test3 test4"></div>
  95. <div class="test1 test2 test3 test4"></div>
  96. <div class="test1 test2 test3 test4"></div>
  97. <div class="test1 test2 test3 test4"></div>
  98. <div class="test1 test2 test3 test4"></div>
  99. <div class="test1 test2 test3 test4"></div>
  100. <div class="test1 test2 test3 test4"></div>
  101. <div class="test1 test2 test3 test4"></div>
  102. <div class="test1 test2 test3 test4"></div>
  103. <div class="test1 test2 test3 test4"></div>
  104. <div class="test1 test2 test3 test4"></div>
  105. <div class="test1 test2 test3 test4"></div>
  106. <div class="test1 test2 test3 test4"></div>
  107. <div class="test1 test2 test3 test4"></div>
  108. <div class="test1 test2 test3 test4"></div>
  109. <div class="test1 test2 test3 test4"></div>
  110. <div class="test1 test2 test3 test4"></div>
  111. <div class="test1 test2 test3 test4"></div>
  112. <div class="test1 test2 test3 test4"></div>
  113. <div class="test1 test2 test3 test4"></div>
  114. <div class="test1 test2 test3 test4"></div>
  115. <div class="test1 test2 test3 test4"></div>
  116. <div class="test1 test2 test3 test4"></div>
  117. <div class="test1 test2 test3 test4"></div>
  118. <div class="test1 test2 test3 test4"></div>
  119. <div class="test1 test2 test3 test4"></div>
  120. <div class="test1 test2 test3 test4"></div>
  121. <div class="test1 test2 test3 test4"></div>
  122. <div class="test1 test2 test3 test4"></div>
  123. <div class="test1 test2 test3 test4"></div>
  124. <div class="test1 test2 test3 test4"></div>
  125. <div class="test1 test2 test3 test4"></div>
  126. <div class="test1 test2 test3 test4"></div>
  127. <div class="test1 test2 test3 test4"></div>
  128. <div class="test1 test2 test3 test4"></div>
  129. <div class="test1 test2 test3 test4"></div>
  130. <div class="test1 test2 test3 test4"></div>
  131. <div class="test1 test2 test3 test4"></div>
  132. <div class="test1 test2 test3 test4"></div>
  133. <div class="test1 test2 test3 test4"></div>
  134. <div class="test1 test2 test3 test4"></div>
  135. <div class="test1 test2 test3 test4"></div>
  136. <div class="test1 test2 test3 test4"></div>
  137. <div class="test1 test2 test3 test4"></div>
  138. <div class="test1 test2 test3 test4"></div>
  139. <div class="test1 test2 test3 test4"></div>
  140. <div class="test1 test2 test3 test4"></div>
  141. <div class="test1 test2 test3 test4"></div>
  142. <div class="test1 test2 test3 test4"></div>
  143. <div class="test1 test2 test3 test4"></div>
  144. <div class="test1 test2 test3 test4"></div>
  145. <div class="test1 test2 test3 test4"></div>
  146. <div class="test1 test2 test3 test4"></div>
  147. <div class="test1 test2 test3 test4"></div>
  148. <div class="test1 test2 test3 test4"></div>
  149. <div class="test1 test2 test3 test4"></div>
  150. <div class="test1 test2 test3 test4"></div>
  151. <div class="test1 test2 test3 test4"></div>
  152. <div class="test1 test2 test3 test4"></div>
  153. <div class="test1 test2 test3 test4"></div>
  154. <div class="test1 test2 test3 test4"></div>
  155. <div class="test1 test2 test3 test4"></div>
  156. <div class="test1 test2 test3 test4"></div>
  157. <div class="test1 test2 test3 test4"></div>
  158. <div class="test1 test2 test3 test4"></div>
  159. <div class="test1 test2 test3 test4"></div>
  160. </div>
  161. </body>
  162. </html>