initial commit
[JIRC.git] / node_modules / jsdom / node_modules / htmlparser / pulls / node-htmlparser / profile.js
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 http = require("http");
6 var htmlparser = require("./node-htmlparser");
7 var libxml = require('./libxmljs');
8
9 var testNHP = true; //Should node-htmlparser be exercised?
10 var testLXJS = true; //Should libxmljs be exercised?
11 var testIterations = 100; //Number of test loops to run
12
13 var testHost = "nodejs.org"; //Host to fetch test HTML from
14 var testPort = 80; //Port on host to fetch test HTML from
15 var testPath = "/api.html"; //Path on host to fetch HTML from
16
17 function getMillisecs () {
18 return((new Date()).getTime());
19 }
20
21 function timeExecutions (loops, func) {
22 var start = getMillisecs();
23
24 while (loops--)
25 func();
26
27 return(getMillisecs() - start);
28 }
29
30 var html = "";
31 http.createClient(testPort, testHost)
32 .request("GET", testPath, { host: testHost })
33 .addListener("response", function (response) {
34 if (response.statusCode == "200") {
35 response.setEncoding("utf8");
36 response.addListener("data", function (chunk) {
37 html += chunk;
38 }).addListener("end", function() {
39 var timeNodeHtmlParser = !testNHP ? 0 : timeExecutions(testIterations, function () {
40 var handler = new htmlparser.DefaultHandler(function(err, dom) {
41 if (err)
42 sys.debug("Error: " + err);
43 });
44 var parser = new htmlparser.Parser(handler);
45 parser.parseComplete(html);
46 })
47
48 var timeLibXmlJs = !testLXJS ? 0 : timeExecutions(testIterations, function () {
49 var dom = libxml.parseHtmlString(html);
50 })
51
52 if (testNHP)
53 sys.debug("NodeHtmlParser: " + timeNodeHtmlParser);
54 if (testLXJS)
55 sys.debug("LibXmlJs: " + timeLibXmlJs);
56 if (testNHP && testLXJS)
57 sys.debug("Difference: " + ((timeNodeHtmlParser - timeLibXmlJs) / timeLibXmlJs) * 100);
58 });
59 }
60 else
61 sys.debug("Error: got response status " + response.statusCode);
62 })
63 .end();