mirror of https://github.com/nodejs/node.git
Add benchmark scripts.
To use the benchmarks: node benchmarks/run.js or: make benchmark The numbers reported are the elapsed milliseconds the script took to complete. Currently only benching HTTP code and timers.
This commit is contained in:
parent
bf6a457f64
commit
05d6319fa0
|
@ -0,0 +1,16 @@
|
|||
function next (i) {
|
||||
if (i <= 0) return;
|
||||
|
||||
var process = node.createProcess("echo hello");
|
||||
|
||||
process.addListener("output", function (chunk) {
|
||||
if (chunk) print(chunk);
|
||||
});
|
||||
|
||||
process.addListener("exit", function (code) {
|
||||
if (code != 0) node.exit(-1);
|
||||
next(i - 1);
|
||||
});
|
||||
}
|
||||
|
||||
next(500);
|
|
@ -0,0 +1,29 @@
|
|||
var benchmarks = [ "static_http_server.js"
|
||||
, "timers.js"
|
||||
, "process_loop.js"
|
||||
];
|
||||
|
||||
var benchmark_dir = node.path.dirname(__filename);
|
||||
|
||||
function exec (script, callback) {
|
||||
var command = ARGV[0] + " " + node.path.join(benchmark_dir, script);
|
||||
var start = new Date();
|
||||
var process = node.createProcess(command);
|
||||
process.addListener("exit", function (code) {
|
||||
var elapsed = new Date() - start;
|
||||
callback(elapsed, code);
|
||||
});
|
||||
}
|
||||
|
||||
function runNext (i) {
|
||||
if (i >= benchmarks.length) return;
|
||||
print(benchmarks[i] + ": ");
|
||||
exec(benchmarks[i], function (elapsed, code) {
|
||||
if (code != 0) {
|
||||
puts("ERROR ");
|
||||
}
|
||||
puts(elapsed);
|
||||
runNext(i+1);
|
||||
});
|
||||
};
|
||||
runNext(0);
|
|
@ -0,0 +1,39 @@
|
|||
var concurrency = 30;
|
||||
var nrequests = 700;
|
||||
var port = 8000;
|
||||
var completed_requests = 0;
|
||||
var bytes = 1024*5;
|
||||
|
||||
var body = "";
|
||||
for (var i = 0; i < bytes; i++) {
|
||||
body += "C";
|
||||
}
|
||||
|
||||
var server = node.http.createServer(function (req, res) {
|
||||
res.sendHeader(200, [
|
||||
["Content-Type", "text/plain"],
|
||||
["Content-Length", body.length]
|
||||
]);
|
||||
res.sendBody(body);
|
||||
res.finish();
|
||||
})
|
||||
server.listen(port);
|
||||
|
||||
function responseListener (res) {
|
||||
res.addListener("complete", function () {
|
||||
//puts("response " + completed_requests + " from client " + res.client.id);
|
||||
if (completed_requests++ < nrequests) {
|
||||
res.client.get("/").finish(responseListener);
|
||||
} else {
|
||||
server.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onLoad () {
|
||||
for (var i = 0; i < concurrency; i++) {
|
||||
var client = node.http.createClient(port);
|
||||
client.id = i;
|
||||
client.get("/").finish(responseListener);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
function next (i) {
|
||||
if (i <= 0) return;
|
||||
setTimeout(function () { next(i-1); }, 1);
|
||||
}
|
||||
next(700);
|
|
@ -100,6 +100,12 @@ test: all
|
|||
test-all: all
|
||||
python tools/test.py --mode=debug,release
|
||||
|
||||
test-debug: all
|
||||
python tools/test.py --mode=release,debug
|
||||
|
||||
benchmark: all
|
||||
build/default/node benchmark/run.js
|
||||
|
||||
website: website/api.html website/index.html
|
||||
|
||||
website/api.html: website/api.txt
|
||||
|
@ -123,7 +129,7 @@ check:
|
|||
dist:
|
||||
@$WAF dist
|
||||
|
||||
.PHONY: clean dist distclean check uninstall install all test test-all website website-upload
|
||||
.PHONY: benchmark clean dist distclean check uninstall install all test test-all website website-upload
|
||||
|
||||
EOF
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue