newparser.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //node --prof --prof_auto profile.js
  2. //deps/v8/tools/mac-tick-processor v8.log
  3. var sys = require("sys");
  4. var fs = require("fs");
  5. var testHtml = "./testdata/api.html"; //Test HTML file to load
  6. var testIterations = 100; //Number of test loops to run
  7. var html = fs.readFileSync(testHtml).toString();
  8. function getMillisecs () {
  9. return((new Date()).getTime());
  10. }
  11. function timeExecutions (loops, func) {
  12. var start = getMillisecs();
  13. while (loops--)
  14. func();
  15. return(getMillisecs() - start);
  16. }
  17. sys.puts("HTML Length: " + html.length);
  18. sys.puts("Test 1: " + timeExecutions(testIterations, function () {
  19. // function parseText (data) {
  20. // //
  21. // }
  22. // function parseTag (data) {
  23. // //
  24. // }
  25. // function parseAttrib (data) {
  26. // //
  27. // }
  28. // function parseComment (data) {
  29. // //
  30. // }
  31. var data = html.split("");
  32. data.meta = {
  33. length: data.length
  34. , pos: 0
  35. }
  36. while (data.meta.length > data.meta.pos && data[data.meta.pos++] !== "");
  37. // sys.puts("Found: " + [data.meta.pos, data[data.meta.pos]]);
  38. }) + "ms");
  39. sys.puts("Test 2: " + timeExecutions(testIterations, function () {
  40. var data = html;
  41. var dataLen = data.length;
  42. var pos = 0;
  43. while (dataLen > pos && data.charAt(pos++) !== "");
  44. // sys.puts("Found: " + [pos, data.charAt(pos)]);
  45. }) + "ms");