Created
May 10, 2012 01:52
-
-
Save alanclarke/2650401 to your computer and use it in GitHub Desktop.
vert.x vs node.js benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********** | |
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