[Pkg-javascript-commits] [ltx] 232/469: browser_benchmark: node compatibility

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:07 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 a4fd8aef85ab51c54028d1baa0a6851b870f830e
Author: Astro <astro at spaceboyz.net>
Date:   Tue Mar 20 14:34:39 2012 +0100

    browser_benchmark: node compatibility
---
 benchmark/browser_benchmark.js | 63 ++++++++++++++++++++++++++++--------------
 1 file changed, 43 insertions(+), 20 deletions(-)

diff --git a/benchmark/browser_benchmark.js b/benchmark/browser_benchmark.js
index bc8a175..86e9f9b 100644
--- a/benchmark/browser_benchmark.js
+++ b/benchmark/browser_benchmark.js
@@ -1,7 +1,11 @@
-var ltx = require("ltx");
-var strophe = require('Strophe.js');
+if (process.title === 'browser') {
+    var ltx = require("ltx");
+    var strophe = require('Strophe.js');
+    var requestAnimationFrame = require('request-animation-frame').requestAnimationFrame;
+} else {
+    var ltx = require("../lib/index");
+}
 var util = require('util');
-var requestAnimationFrame = require('request-animation-frame').requestAnimationFrame;
 
 function now() {
     return new Date().getTime();
@@ -23,14 +27,23 @@ Test.prototype = {
     },
 
     report: function() {
-	var s = [];
-	var html = "<div style='float: left; min-width: 25em'><h2>" + this.name + "</h2><dl>";
-	for(var k in this.timings) {
-	    var t = this.timings[k].t / this.timings[k].i;
-	    html += "<dt>" + k + "</dt><dd class='" + k + "'>" + t + " ms </dd>";
+	if (process.title === 'browser') {
+	    var s = [];
+	    var html = "<div style='float: left; min-width: 25em'><h2>" + this.name + "</h2><dl>";
+	    for(var k in this.timings) {
+		var t = this.timings[k].t / this.timings[k].i;
+		html += "<dt>" + k + "</dt><dd class='" + k + "'>" + t + " ms </dd>";
+	    }
+	    html += "</dl></div>\n";
+	    return html;
+	} else {
+	    var s = this.name + "\t";
+	    for(k in this.timings) {
+		var t = this.timings[k].t / this.timings[k].i;
+		s += k + ": " + t + " ms\t";
+	    }
+	    return s;
 	}
-	html += "</dl></div>\n";
-	return html;
     }
 };
 
@@ -64,16 +77,19 @@ StropheTest.prototype.parse = function(s) {
     return Strophe.xmlHtmlNode(s).firstChild;
 };
 
-StropheTest.prototype.serialize = Strophe.serialize;
+if (this.Strophe)
+    StropheTest.prototype.serialize = Strophe.serialize;
 
 StropheTest.prototype.traverse = function(node) {
     while(node.firstChild)
 	node = node.firstChild;
 };
 
-var tests = [new StropheTest()].concat(ltx.availableSaxParsers.map(function(saxParser) {
+var tests = ltx.availableSaxParsers.map(function(saxParser) {
     return new LtxTest(saxParser);
-}));
+});
+if (process.title === 'browser')
+    tests.push(new StropheTest());
 var messages = [
     "<message/>",
     "<message foo='bar'/>",
@@ -106,13 +122,20 @@ function runTests() {
 	}
     });
 
-    document.body.innerHTML = "<style>.parse0, .parse1, .parse2, .parse3 { color: red; } .serialize1, .serialize2, .serialize3, .serialize4 { color: blue; }</style>\n" +
-	"<h1>Iteration " + iteration + "<h1>\n";
-    tests.forEach(function(test) {
-	document.body.innerHTML += test.report() + "<br>";
-    });
-
-    requestAnimationFrame(runTests);
+    if (process.title === 'browser') {
+	document.body.innerHTML = "<style>.parse0, .parse1, .parse2, .parse3 { color: red; } .serialize1, .serialize2, .serialize3, .serialize4 { color: blue; }</style>\n" +
+	    "<h1>Iteration " + iteration + "<h1>\n";
+	tests.forEach(function(test) {
+	    document.body.innerHTML += test.report() + "<br>";
+	});
+	requestAnimationFrame(runTests);
+    } else {
+	console.log("Iteration " + iteration);
+	tests.forEach(function(test) {
+	    console.log(test.report());
+	});
+	process.nextTick(runTests);
+    }
 }
 
 setTimeout(function() {

-- 
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