Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: regality/node
...
head fork: regality/node
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 24 additions and 27 deletions.
  1. +24 −27 benchmark/http_simple.js
View
51 benchmark/http_simple.js
@@ -11,26 +11,6 @@ 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 = {};
@@ -39,6 +19,7 @@ var server = http.createServer(function (req, res) {
var command = commands[1];
var body = "";
var arg = commands[2];
+ var n_chunks = parseInt(commands[3], 10);
var status = 200;
if (command == "bytes") {
@@ -73,19 +54,32 @@ var server = http.createServer(function (req, res) {
} else if (command == "fixed") {
body = fixed;
- } else if (command == "info") {
- body = 'rev=' + rev + '\nuname="' + uname + '"\n';
-
} else {
status = 404;
body = "not found\n";
}
- var content_length = body.length.toString();
+ // example: http://localhost:port/bytes/512/4
+ // sends a 512 byte body in 4 chunks of 128 bytes
+ if (n_chunks > 0) {
+ res.writeHead(status, { "Content-Type": "text/plain",
+ "Transfer-Encoding": "chunked" });
+ // send body in chunks
+ var len = body.length;
+ var step = ~~(len / n_chunks) || len;
+
+ for (var i = 0; i < len; i += step) {
+ res.write(body.slice(i, i + step));
+ }
- res.writeHead(status, { "Content-Type": "text/plain",
- "Content-Length": content_length });
- res.end(body);
+ res.end();
+ } else {
+ var content_length = body.length.toString();
+
+ res.writeHead(status, { "Content-Type": "text/plain",
+ "Content-Length": content_length });
+ res.end(body);
+ }
});
@@ -93,3 +87,6 @@ server.listen(port, function () {
console.log('Listening at http://127.0.0.1:'+port+'/');
});
+process.on('exit', function() {
+ console.error('libuv counters', process.uvCounters());
+});

No commit comments for this range

Something went wrong with that request. Please try again.