Thursday, 16 February 2012

XQuery parser in Javascript performance

"even more scary is how lightning fast the exact same program is in javascript... "
@wcandillon

What are the numbers?

Gunther Rademacher's REX parser generator can target several languages including Javascript.

The Javascript output is designed for jrunscript. To see what it expects use the option:
Main program=simple
jrunscript did not work for me, nor did Rhino, probably  due to my lack of familiarity  with these tools.
I wanted to run using Node.js and this required a few changes to the javascript
  1. changing  the writeOutput function to capture the result 
  2. setting the module exports module.exports = xquery30
The node main module is:

var Xq=require("./xq3.js");
var out=[];
var parser=new Xq("2+3",out);
parser.parse_XQuery();
console.log(out.join("")); 

The numbers:

time node app.js
real 0m0.278s
user 0m0.212s
sys 0m0.020s
No doubt the c++ is faster. Perhaps the winner is EBNF.

Github: xqparserperf 

No comments:

Post a Comment