Skip to content

Instantly share code, notes, and snippets.

@philiptzou
Last active November 8, 2015 09:17
Show Gist options
  • Save philiptzou/8db4b05aa6d03cb7691d to your computer and use it in GitHub Desktop.
Save philiptzou/8db4b05aa6d03cb7691d to your computer and use it in GitHub Desktop.
Node CGI vs. HTTP server
process.stdout.write("Hello world!");
var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello world!");
response.end();
});
server.listen(7777);
console.log("Server is listening");
import timeit
import requests
print 'CGI: %.4fs' % timeit.timeit("subprocess.check_output(['node', 'cgi.js'])",
'import subprocess', number=100)
print 'HTTP: %.4fs' % timeit.timeit("requests.get('http://localhost:7777/').content",
"import requests", number=100)
# run "node http.js" in another console
python2.7 profile.py
CGI: 3.2942s
HTTP: 0.1447s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment