[Pkg-javascript-commits] [ltx] 438/469: add parsers comparison benchmark and update README

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit b059a9460cd0d8cd5482e07475ffbd95b003f049
Author: Sonny Piers <sonny at fastmail.net>
Date:   Wed Mar 30 20:49:49 2016 +0200

    add parsers comparison benchmark and update README
---
 README.md             | 40 ++++++++++++++++++++-----------
 benchmarks/parsers.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md
index 32b963c..181685d 100644
--- a/README.md
+++ b/README.md
@@ -1,36 +1,48 @@
-# Less-Than XML
+ltx
+===
 
-`<xml for=\"JavaScript\">`
+`JavaScript XML library`
 
 [![build status](https://img.shields.io/travis/node-xmpp/ltx/master.svg?style=flat-square)](https://travis-ci.org/node-xmpp/ltx/branches)
 [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
 
-ltx is a fast XML builder, parser and manipulation library for JavaScript.
+ltx is a fast XML builder, parser, serialization and manipulation library for JavaScript.
 
-The builder is a convenient and succinct API to build XML documents represented in memory as JavaScript primitives that can be serialized to XML strings. It provides a [JSX](https://facebook.github.io/jsx/) compatible API as well.
+The builder is a convenient and succinct API to build XML documents represented in memory as JavaScript primitives that can be serialized to XML strings.
 
-The parser can parse XML documents or streams and support different backends.
+The parser can parse XML documents or streams and support [multiple parsers](#parsers).
 
 Features:
-* Succinct API to build and manipulate XML objects
+* succinct API to build and manipulate XML objects
 * parse XML strings
 * parse XML streams
-* multiple parser backends
-  * [sax-js](https://github.com/isaacs/sax-js)
-  * [node-xml](https://github.com/dylang/node-xml)
-  * [node-expat](https://github.com/node-xmpp/node-expat)
-  * [libxmljs](https://github.com/polotek/libxmljs)
-  * [ltx](https://github.com/node-xmpp/ltx/blob/master/lib/parsers/ltx.js) (default and fastest see [Benchmark](#benchmark))
-* [JSX](https://facebook.github.io/jsx/) compatible (use `ltx.createElement` pragma)
+* [multiple parser backends](#parsers)
+* [JSX](https://facebook.github.io/jsx/) compatible (with `ltx.createElement` pragma)
 * [tagged template](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) support `` ltx`<foo bar="${baz}">` ``
 
 ## Install
 
 `npm install ltx`
 
+## Parsers
+
+By default ltx uses its own parser which is the fastest but doesn't support advanced XML features.
+ltx supports third party parsers when such features are needed.
+
+| parser                                                                                     | ops/sec | native | stream |
+|--------------------------------------------------------------------------------------------|--------:|:------:|:------:|
+| [sax-js](https://github.com/isaacs/sax-js)                                                 |  99,412 | ☐      | ☑      |
+| [node-xml](https://github.com/dylang/node-xml)                                             | 130,631 | ☐      | ☑      |
+| [libxmljs](https://github.com/polotek/libxmljs)                                            | 276,136 | ☑      | ☐      |
+| [node-expat](https://github.com/node-xmpp/node-expat)                                      | 322,769 | ☑      | ☑      |
+| **[ltx/lib/parsers/ltx](https://github.com/node-xmpp/ltx/blob/master/lib/parsers/ltx.js)** | 641,327 | ☐      | ☑      |
+
+
+From [ltx/benchmarks/parsers.js](https://github.com/node-xmpp/ltx/blob/master/benchmarks/parsers.js), higher is better.
+
 ## Documentation
 
-For documentation please see http://node-xmpp.org/doc/ltx.html
+http://node-xmpp.org/doc/ltx.html
 
 ## Benchmark
 
diff --git a/benchmarks/parsers.js b/benchmarks/parsers.js
new file mode 100644
index 0000000..9a1f385
--- /dev/null
+++ b/benchmarks/parsers.js
@@ -0,0 +1,66 @@
+'use strict'
+
+var benchmark = require('benchmark')
+var node_xml = require('node-xml')
+var libxml = require('libxmljs')
+var expat = require('node-expat')
+var sax = require('sax')
+// var ltx = require('..')
+var LtxSaxParser = require('../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('XML parsers comparison')
+
+parsers.forEach(function (parser) {
+  parser.parse('<r>')
+  suite.add(parser.name, function () {
+    parser.parse('<foo bar="baz">quux</foo>')
+  })
+})
+
+module.exports = suite

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list