forked from tautologistics/node-htmlparser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.js
63 lines (54 loc) · 1.91 KB
/
profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//node --prof --prof_auto profile.js
//deps/v8/tools/mac-tick-processor v8.log
var sys = require("sys");
var fs = require("fs");
var http = require("http");
var htmlparser = require("./lib/htmlparser");
//var libxml = require('./libxmljs');
var testNHP = true; //Should node-htmlparser be exercised?
var testLXJS = false; //Should libxmljs be exercised?
var testIterations = 100; //Number of test loops to run
var testHost = "localhost"; //Host to fetch test HTML from
var testPort = 80; //Port on host to fetch test HTML from
var testPath = "/~chris/feed.xml"; //Path on host to fetch HTML from
function getMillisecs () {
return((new Date()).getTime());
}
function timeExecutions (loops, func) {
var start = getMillisecs();
while (loops--)
func();
return(getMillisecs() - start);
}
var html = "";
http.createClient(testPort, testHost)
.request("GET", testPath, { host: testHost })
.addListener("response", function (response) {
if (response.statusCode == "200") {
response.setEncoding("utf8");
response.addListener("data", function (chunk) {
html += chunk;
}).addListener("end", function() {
var timeNodeHtmlParser = !testNHP ? 0 : timeExecutions(testIterations, function () {
var handler = new htmlparser.DefaultHandler(function(err, dom) {
if (err)
sys.debug("Error: " + err);
});
var parser = new htmlparser.Parser(handler, { includeLocation: true });
parser.parseComplete(html);
})
var timeLibXmlJs = !testLXJS ? 0 : timeExecutions(testIterations, function () {
var dom = libxml.parseHtmlString(html);
})
if (testNHP)
sys.debug("NodeHtmlParser: " + timeNodeHtmlParser);
if (testLXJS)
sys.debug("LibXmlJs: " + timeLibXmlJs);
if (testNHP && testLXJS)
sys.debug("Difference: " + ((timeNodeHtmlParser - timeLibXmlJs) / timeLibXmlJs) * 100);
});
}
else
sys.debug("Error: got response status " + response.statusCode);
})
.end();