diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-10-14 01:16:49 +0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-14 01:30:50 +0400 |
commit | cdde22a27d797b853efac161eaec630d3405e924 (patch) | |
tree | 804a3d5c17493745461aa0ab21f251b26474ebe8 /benchmark | |
parent | 9b1ff070e6df8560ec4ce60d78c68c96ddf206c8 (diff) |
Improve benchmark/http_simple.js
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/http_simple.js | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 446b3b33f40..93903c42a92 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -1,24 +1,40 @@ path = require("path"); -Buffer = require("buffer").Buffer; +exec = require("child_process").exec; +http = require("http"); port = parseInt(process.env.PORT || 8000); -var old = (process.argv[2] == 'old'); - console.log('pid ' + process.pid); -http = require(old ? "http_old" : 'http'); -if (old) console.log('old version'); - fixed = "" for (var i = 0; i < 20*1024; i++) { fixed += "C"; } +var uname, rev; + +exec('git rev-list -1 HEAD', function (e, stdout) { + if (e) { + console.error("Problem executing: 'git rev-list -1 HEAD'"); + throw new Error(e); + } + rev = stdout.replace(/\s/g, ''); +}); + +exec('uname -a', function (e, stdout) { + if (e) { + console.error("Problem executing: 'uname -a'"); + throw new Error(e); + } + uname = stdout.replace(/[\r\n]/g, ''); +}); + + + stored = {}; storedBuffer = {}; -http.createServer(function (req, res) { +var server = http.createServer(function (req, res) { var commands = req.url.split("/"); var command = commands[1]; var body = ""; @@ -57,6 +73,9 @@ http.createServer(function (req, res) { } else if (command == "fixed") { body = fixed; + } else if (command == "info") { + body = 'rev: ' + rev + '\n' + 'uname: ' + uname + '\n'; + } else { status = 404; body = "not found\n"; @@ -64,17 +83,13 @@ http.createServer(function (req, res) { var content_length = body.length.toString(); - res.writeHead( status - , { "Content-Type": "text/plain" - , "Content-Length": content_length - } - ); - if (old) { - res.write(body, 'ascii'); - res.close(); - } else { - res.end(body, 'ascii'); - } -}).listen(port); + res.writeHead(status, { "Content-Type": "text/plain", + "Content-Length": content_length }); + res.end(body); + +}); + +server.listen(port, function () { + console.log('Listening at http://127.0.0.1:'+port+'/'); +}); -console.log('Listening at http://127.0.0.1:'+port+'/'); |