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');
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
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
17 function getMillisecs () {
18 return((new Date()).getTime());
21 function timeExecutions (loops
, func
) {
22 var start
= getMillisecs();
27 return(getMillisecs() - start
);
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
) {
38 }).addListener("end", function() {
39 var timeNodeHtmlParser
= !testNHP
? 0 : timeExecutions(testIterations
, function () {
40 var handler
= new htmlparser
.DefaultHandler(function(err
, dom
) {
42 sys
.debug("Error: " + err
);
44 var parser
= new htmlparser
.Parser(handler
);
45 parser
.parseComplete(html
);
48 var timeLibXmlJs
= !testLXJS
? 0 : timeExecutions(testIterations
, function () {
49 var dom
= libxml
.parseHtmlString(html
);
53 sys
.debug("NodeHtmlParser: " + timeNodeHtmlParser
);
55 sys
.debug("LibXmlJs: " + timeLibXmlJs
);
56 if (testNHP
&& testLXJS
)
57 sys
.debug("Difference: " + ((timeNodeHtmlParser
- timeLibXmlJs
) / timeLibXmlJs
) * 100);
61 sys
.debug("Error: got response status " + response
.statusCode
);