From 148ba49cdeb8009665a89a9c31abf0bc1ce056ff Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Tue, 19 Jul 2011 06:07:45 +1000 Subject: [PATCH] added 'lost in merge' wndwrap; t61/ubuntu benchmarks --- test/atom_benchmark_buffered.js | 20 ++++++---- test/atom_benchmark_parallel.js | 21 +++++++--- test/testwnd.js | 37 +++++++++++++++++ test/wndwrap.js | 70 +++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 test/testwnd.js create mode 100644 test/wndwrap.js diff --git a/test/atom_benchmark_buffered.js b/test/atom_benchmark_buffered.js index 607bc38..7b97c86 100644 --- a/test/atom_benchmark_buffered.js +++ b/test/atom_benchmark_buffered.js @@ -1,15 +1,21 @@ -// WinServ2008R2 64bit, Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz + Xming 6.9.0.31 +// WinServ2008R2 64bit, Intel(R) Core(TM) i7 CPU 870 @2.93GHz, Xming 6.9.0.31 // 0.4.3/cygwin 32bit: 12000 +/-1000 InternAtom/sec // 0.5.1/win32 : 12000 +/-1000 +// Ubuntu 11.04 32bit, Intel(R) Core(TM)2 Duo CPU T7250 @2.00GHz, XOrg 1:7.6+4ubuntu3.1 +// 0.4.9pre: 23300 +/-200 + + var x11 = require('../lib/x11'); var xclient = x11.createClient(); var counter = 0; var t = +new Date(); var t0 = t; -var num = 10000; +var num = 100000; xclient.on('connect', function(display) { + console.log(display); + process.exit(0); var X = this; for (var i=0; i < num; ++i) { @@ -22,16 +28,16 @@ xclient.on('connect', function(display) { t = t1; } //console.log('atom %d saved on server', atomId); - /* - if ((counter % 1000) == 0) + + if ((counter % 10000) == 0) { var t1 = +new Date(); - console.log('received 1000 (up to %d) atom ids in %d ms', counter, t1 - t); + console.log('received 10000 (up to %d) atom ids in %d ms', counter, t1 - t); t = t1; } - */ + counter++; - if (counter == num) + if (counter == (num-1)) { var t1 = +new Date(); var delta = t1 - t0; diff --git a/test/atom_benchmark_parallel.js b/test/atom_benchmark_parallel.js index 47541ba..afde735 100644 --- a/test/atom_benchmark_parallel.js +++ b/test/atom_benchmark_parallel.js @@ -1,8 +1,13 @@ // test results: // WinServ2008R2, Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz + Xming 6.9.0.31 +// // 0.4.3/cygwin 32bit : 8500 +/- 2000 InternAtom/sec // 0.5.1/win32 : N/A +// +// Ubuntu 11.04 32bit, Intel(R) Core(TM)2 Duo CPU T7250 @2.00GHz, XOrg 1:7.6+4ubuntu3.1 +// 0.4.9pre: 16700 +/-300 + var x11 = require('../lib/x11'); @@ -10,8 +15,6 @@ var xclient = x11.createClient(); var reqcounter = 0; var rescounter = 0; -var t = +new Date(); -var t0 = t; var num = 400000; var X; @@ -25,9 +28,16 @@ function benchmarkAtoms() X.InternAtom(false, 'test ' + reqcounter, function(atomId) { rescounter++; //console.log('%d received', rescounter); - //if ( (rescounter % 1000) == 0) - // console.log(reqcounter - rescounter); - if (rescounter == num) + if ( (rescounter % 10000) == 0) + { + var t2 = X.t1; + X.t1 = +new Date(); + var delta = X.t1 - t2; + console.log(reqcounter - rescounter); + console.log('reqs/msec: ' + 10000/delta); + console.log('msec per req: ' + delta/10000); + } + if (rescounter == (num-2)) { var t1 = +new Date(); var delta = t1 - t0; @@ -48,5 +58,6 @@ function benchmarkAtoms() xclient.on('connect', function(display) { X = this; + X.t1 = +new Date(); benchmarkAtoms(); }); diff --git a/test/testwnd.js b/test/testwnd.js new file mode 100644 index 0000000..5097fe9 --- /dev/null +++ b/test/testwnd.js @@ -0,0 +1,37 @@ +var x11 = require('../lib/x11'); +var Window = require('./wndwrap'); + +var width = 700; +var height = 500; + +var xclient = x11.createClient(); +xclient.on('connect', function(display) { + var white = xclient.display.screen[0].white_pixel; + var black = xclient.display.screen[0].black_pixel; + + var mainwnd = new Window(xclient, 0, 0, width, height, white); + mainwnd.on('mousemove', function(ev) { + console.log(ev.x, ev.y); + }); + var ch = new Window(mainwnd, 10, 10, 50, 70, black); + ch.on('mousemove', function(ev) { + console.log(ev); + //ch.unmap(); + //setTimeout( function() { ch.map() }, 500); + }); + + mainwnd.map(); + /* + for (var x = 0; x < width; x += 20) { + for (var y = 0; y < width; y += 20) { + // TODO: wnd.createChild() ? + var ch = new Window(mainwnd, x + 1, y + 1, 18, 18, 0, black); + //ch.map(); + ch.on('mousemove', function(ev) { + ch.unmap(); + setTimeout( function() { ch.map() }, 500); + }); + } + } + */ +}); diff --git a/test/wndwrap.js b/test/wndwrap.js new file mode 100644 index 0000000..f0cb058 --- /dev/null +++ b/test/wndwrap.js @@ -0,0 +1,70 @@ +var EventEmitter = require('events').EventEmitter; +var util = require('util'); // util.inherits + +function Window(parent, x, y, w, h, bg) +{ + if (parent.constructor && parent.constructor.name == 'XClient') + { + this.xclient = parent; + if (!this.xclient.rootWindow) + { + // quick hack + var rootWnd = { + id: this.xclient.display.screen[0].root, + xclient: this.xclient + }; + rootWnd.parent = null; + this.parent = this.xclient.rootWnd; + this.xclient.rootWindow = rootWnd; + } + this.parent = this.xclient.rootWindow; + } else { + this.parent = parent; + this.xclient = parent.xclient; + } + + this.x = x; + this.y = y; + this.w = w; + this.h = h; + this.bg = bg; + this.id = this.xclient.AllocID(); + + var borderWidth = 1; + var _class = 1; // InputOutput + var visual = 0; // CopyFromParent + this.xclient.CreateWindow( + this.id, this.parent.id, this.x, this.y, this.w, this.h, + borderWidth, _class, visual, + { + backgroundPixel: this.bg, + eventMask: 0x00000040 + } + ); + //this.map(); + + var wnd = this; + eventType2eventName = { + 6: 'mousemove' + }; + + var ee = new EventEmitter(); + this.xclient.event_consumers[wnd.id] = ee; + // TODO: do we need to have wnd as EventEmitter AND EventEmitter stored in event_consumers ? + ee.on('event', function( ev ) + { + wnd.emit(eventType2eventName[ev.type], ev); // convert to mousemove? (ev is already event-spacific) + }); + // TODO: track delete events and remove wmd from consumers list +} +util.inherits(Window, EventEmitter); + +Window.prototype.map = function() { + this.xclient.MapWindow(this.id); +} + +Window.prototype.unmap = function() { + this.xclient.UnmapWindow(this.id); +} + +module.exports = Window;