#!/usr/bin/env node

process.stdin.setEncoding("utf8");

var fs      = require("fs"),
    fname   = process.argv[2] || "example",
    transit = require("../target/transit.js"),
    r       = transit.reader(),
    jstr    = fs.readFileSync("resources/"+fname+".json", "utf-8");
    tstr    = fs.readFileSync("resources/"+fname+".tjs", "utf-8");

function time(f, iters) {
    iters = iters || 1;
    for(var i = 0; i < iters; i++) {
        var s = new Date();
        f();
        console.log("Elapsed "+((new Date()).valueOf()-s.valueOf())+"ms");
        console.log("----------");
    }
}

console.log("JSON.parse 100 iters", JSON.parse(jstr).length);
time(function() {
    for(var i = 0; i < 100; i++) {
        JSON.parse(jstr);
    }
}, 5);

console.log("JSON.parse transit JSON 100 iters", JSON.parse(tstr).length);
time(function() {
    for(var i = 0; i < 100; i++) {
        JSON.parse(tstr);
    }
}, 5);

console.log("transit read 100 iters", r.read(tstr).length);
time(function() {
    for(var i = 0; i < 100; i++) {
        r.read(tstr);
    }
}, 5);

@@ -123,16 +123,85 @@
 ample%22,%0A
+    iter    = process.argv%5B3%5D ? parseInt(process.argv%5B3%5D, 10) : 100,%0A
     tran
@@ -682,43 +682,23 @@
 rse 
-100 iters%22, JSON.parse(jstr).length
+%22+iter+%22 iters%22
 );%0At
@@ -729,35 +729,36 @@
 (var i = 0; i %3C 
-100
+iter
 ; i++) %7B%0A       
@@ -831,43 +831,23 @@
 SON 
-100 iters%22, JSON.parse(tstr).length
+%22+iter+%22 iters%22
 );%0At
@@ -878,35 +878,36 @@
 (var i = 0; i %3C 
-100
+iter
 ; i++) %7B%0A       
@@ -969,39 +969,23 @@
 ead 
-100 iters%22, r.read(tstr).length
+%22+iter+%22 iters%22
 );%0At
@@ -1024,19 +1024,20 @@
  0; i %3C 
-100
+iter
 ; i++) %7B

allow supplying iter to bench/json.js