forked from creationix/http-parser-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
47 lines (42 loc) · 1.05 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
if (process.env.USE_JS) {
process.binding("http_parser").HTTPParser = require('./http_parser').HTTPParser;
}
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {
"Content-Length": 12,
"Content-Type": "text/plain"
});
res.end("Hello World\n");
});
server.listen(8080, function () {
var port = server.address().port;
var url = "http://127.0.0.1:" + port + "/";
console.log(url);
var params = {
method: "GET",
host: "127.0.0.1",
path: "/",
port: 8080
};
if (process.env.NODE_CLIENT) {
function request() {
var req = http.request(params, function (res) {
count++;
request();
});
req.end();
}
request();
var count = 0;
var before = Date.now();
setInterval(function () {
var now = Date.now();
var delta = now - before;
before = now;
var rps = Math.round(count / delta * 1000);
console.log("%s req/second (%s reqs in %s ms)", rps, count, delta);
count = 0;
}, 1000);
}
});