forked from xmppo/node-expat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
60 lines (56 loc) · 1.22 KB
/
bench.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
var util = require('util');
var node_xml = require("node-xml");
var libxml = require("libxmljs");
var expat = require('node-expat');
var sax = require('sax');
function NodeXmlParser() {
var parser = new node_xml.SaxParser(function(cb) { });
this.parse = function(s) {
parser.parseString(s);
};
}
function LibXmlJsParser() {
var parser = new libxml.SaxPushParser(function(cb) { });
this.parse = function(s) {
parser.push(s, false);
};
}
function SaxParser() {
var parser = sax.parser();
this.parse = function(s) {
parser.write(s).close();
}
}
function ExpatParser() {
var parser = new expat.Parser();
this.parse = function(s) {
parser.parse(s, false);
};
}
//var p = new NodeXmlParser();
//var p = new LibXmlJsParser();
//var p = new SaxParser();
var p = new ExpatParser();
p.parse("<r>");
var nEl = 0;
function d() {
p.parse("<foo bar='baz'>quux</foo>");
nEl++;
setTimeout(d, 0);
}
d();
var its =[];
setInterval(function() {
util.puts(nEl + " el/s");
its.push(nEl);
nEl = 0;
}, 1000);
process.on('SIGINT', function () {
var average = 0;
its.forEach(function (v){
average += v;
});
average /= its.length;
util.puts("Average: " + average + " el/s");
process.exit(0);
});