[Pkg-javascript-commits] [node-expat] 01/34: benchmark
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 10:46:47 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-expat.
commit b86cad27a35f6362089b7743174d3b98576407c9
Author: Sonny Piers <sonny at fastmail.net>
Date: Fri Dec 11 14:59:43 2015 +0100
benchmark
---
README.md | 22 +++++++++++++------
bench.js | 61 ---------------------------------------------------
benchmark.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package.json | 10 +++++----
4 files changed, 92 insertions(+), 72 deletions(-)
diff --git a/README.md b/README.md
index 472403e..3426340 100644
--- a/README.md
+++ b/README.md
@@ -20,13 +20,21 @@ npm install node-expat
## Testing
-If not already available globally, you'll need to install the
-[standard](http://standardjs.com/) code style checker.
-
-```
-npm install standard
-```
-
```
+npm install -g standard
npm test
```
+
+## Benchmark
+
+```node benchmark.js```
+
+| module | ops/sec | native | XML compliant |
+|--------------------|--------:|:------:|:-------------:|
+| sax | 18,641 | ☐ | ☑ |
+| node-xml | 49,257 | ☐ | ☑ |
+| libxmljs | 95,169 | ☑ | ☑ |
+| **node-expat** | 130,776 | ☑ | ☑ |
+| ltx/lib/parsers/ltx| 172,596 | ☐ | ☐ |
+
+Higher is better. Please note that ltx parser is not entirely XML compliant.
diff --git a/bench.js b/bench.js
deleted file mode 100644
index 2bf7a0e..0000000
--- a/bench.js
+++ /dev/null
@@ -1,61 +0,0 @@
-'use strict'
-
-var node_xml = require('node-xml')
-var libxml = require('libxmljs')
-var expat = require('./')
-var sax = require('sax')
-
-function NodeXmlParser () { // eslint-disable-line
- var parser = new node_xml.SaxParser(function (cb) {})
- this.parse = function (s) {
- parser.parseString(s)
- }
-}
-function LibXmlJsParser () { // eslint-disable-line
- var parser = new libxml.SaxPushParser(function (cb) {})
- this.parse = function (s) {
- parser.push(s, false)
- }
-}
-function SaxParser () { // eslint-disable-line
- 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 () {
- console.log(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
- console.log('Average: ' + average + ' el/s')
- process.exit(0)
-})
diff --git a/benchmark.js b/benchmark.js
new file mode 100644
index 0000000..502b1cb
--- /dev/null
+++ b/benchmark.js
@@ -0,0 +1,71 @@
+'use strict'
+
+var benchmark = require('benchmark')
+var node_xml = require('node-xml')
+var libxml = require('libxmljs')
+var expat = require('./')
+var sax = require('sax')
+var LtxSaxParser = require('ltx/lib/parsers/ltx')
+
+function NodeXmlParser () {
+ var parser = new node_xml.SaxParser(function (cb) {})
+ this.parse = function (s) {
+ parser.parseString(s)
+ }
+ this.name = 'node-xml'
+}
+function LibXmlJsParser () {
+ var parser = new libxml.SaxPushParser(function (cb) {})
+ this.parse = function (s) {
+ parser.push(s, false)
+ }
+ this.name = 'libxmljs'
+}
+function SaxParser () {
+ var parser = sax.parser()
+ this.parse = function (s) {
+ parser.write(s).close()
+ }
+ this.name = 'sax'
+}
+function ExpatParser () {
+ var parser = new expat.Parser()
+ this.parse = function (s) {
+ parser.parse(s, false)
+ }
+ this.name = 'node-expat'
+}
+function LtxParser () {
+ var parser = new LtxSaxParser()
+ this.parse = function (s) {
+ parser.write(s)
+ }
+ this.name = 'ltx'
+}
+
+var parsers = [
+ SaxParser,
+ NodeXmlParser,
+ LibXmlJsParser,
+ ExpatParser,
+ LtxParser
+].map(function (Parser) {
+ return new Parser()
+})
+
+var suite = new benchmark.Suite('parse')
+
+parsers.forEach(function (parser) {
+ parser.parse('<r>')
+ suite.add(parser.name, function () {
+ parser.parse('<foo bar="baz">quux</foo>')
+ })
+})
+
+suite.on('cycle', function (event) {
+ console.log(event.target.toString())
+})
+ .on('complete', function () {
+ console.log('Fastest is ' + this.filter('fastest').pluck('name'))
+ })
+ .run({'async': true})
diff --git a/package.json b/package.json
index a4231c4..2b6e9f9 100644
--- a/package.json
+++ b/package.json
@@ -22,8 +22,13 @@
"nan": "^2.1.0"
},
"devDependencies": {
+ "benchmark": "^1.0.0",
"debug": "^2.2.0",
"iconv": "^2.1.10",
+ "libxmljs": "^0.16.1",
+ "ltx": "^2.2.0",
+ "node-xml": "^1.0.2",
+ "sax": "^1.1.4",
"vows": "^0.8.1"
},
"repository": "github:node-xmpp/node-expat",
@@ -57,8 +62,5 @@
"Julien Genestoux",
"Sonny Piers"
],
- "license": "MIT",
- "engines": {
- "node": ">=0.8"
- }
+ "license": "MIT"
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git
More information about the Pkg-javascript-commits
mailing list