Skip to content

Instantly share code, notes, and snippets.

@alanclarke
Created May 10, 2012 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanclarke/2650401 to your computer and use it in GitHub Desktop.
Save alanclarke/2650401 to your computer and use it in GitHub Desktop.
vert.x vs node.js benchmark
/**********
instead of:
***********/
//taken from https://github.com/purplefox/vert.x/blob/master/src/examples/java/httpperf/nodejs-server.js
http.createServer(function (req, res) {
//asynchronous callback and file read on every request
fs.readFile("foo.html", function(err, file) {
if (err) {
console.error(err);
} else {
res.writeHead(200, {"Content-Type": "text/html", "Content-Length": file.length});
res.write(file);
res.end();
}
});
}).listen(8080, 'localhost');
/**********
try:
***********/
//explicitly cached variable
var file = fs.readFileSync("foo.html");
http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/html", "Content-Length": file.length});
res.write(file);
res.end();
}).listen(8080, 'localhost');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment