Skip to content

Instantly share code, notes, and snippets.

@shaoshing
Created February 11, 2014 03:38
Show Gist options
  • Save shaoshing/8928883 to your computer and use it in GitHub Desktop.
Save shaoshing/8928883 to your computer and use it in GitHub Desktop.
Benchmarking Node.js and Golang
echo "\n\n# Benchmarking Golang"
go build server.go
./server &
PID=$!
sleep 2
ab -c 100 -n 10000 http://127.0.0.1:8000/
kill $PID
echo "\n\n# Benchmarking Node.js"
node server.js &
PID=$!
sleep 2
ab -c 100 -n 10000 http://127.0.0.1:8000/
kill $PID
package main
import "net/http"
import "log"
func main() {
bytes := make([]byte, 1024*1024)
for i, _ := range bytes{
bytes[i] = 100
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(bytes)
})
log.Println("Server running at http://127.0.0.1:8000/")
http.ListenAndServe(":8000", nil)
}
var buffer = new Buffer(1024*1024);
for (var i = 0; i < buffer.length; i++)
buffer[i] = 100;
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(buffer);
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment