From 4198ea456fd4280ff414b12a62fc45caa1aa9c69 Mon Sep 17 00:00:00 2001 From: javi santana Date: Thu, 13 Oct 2011 15:24:25 +0200 Subject: [PATCH] added wip benchmark tool --- test/benchmark.js | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/benchmark.js diff --git a/test/benchmark.js b/test/benchmark.js new file mode 100644 index 00000000..ac8fa3ad --- /dev/null +++ b/test/benchmark.js @@ -0,0 +1,48 @@ +// small benchmark to execute with nodejs + +var http = require('http') + +var options = { + host: 'vizzuality.localhost.lan', + port: 80, + path: '/tiles/datos_agroguia_2/{z}/{x}/{y}.png?cache_buster=0&map_key=a9edf3d0d2edbcf55ad38ee5b23af1507b774a5b' +}; + +function randInt(min, max) { + return min + Math.floor(Math.random()*(max- min +1)); +} + +var start_time = new Date().getTime(); +function end() { + var end_time = new Date().getTime(); + var t = (end_time - start_time)/1000; + console.log("ok: ", ok) + console.log("error: ", error) + console.log("time: ", t); + console.log("req/s: ", ok/t); +} + +var N = 1000 +var ok = 0; +var error = 0; +for(var i = 0; i < N; ++i) { + var opt = { + host: options.host, + port: options.port, + path: new String(options.path) + }; + opt.path = opt.path.replace('{z}', 2).replace('{x}', randInt(0, 3)).replace('{y}', randInt(0, 3)); + console.log(opt.path) + http.get(opt, function(res) { + //console.log(ok + error); + ok++; + if(ok + error === N) + end(); + }).on('error', function(e) { + //console.log(ok + error); + error ++; + if(ok + error === N) + end(); + }); +} +