Created
February 11, 2014 03:38
-
-
Save shaoshing/8928883 to your computer and use it in GitHub Desktop.
Benchmarking Node.js and Golang
This file contains hidden or 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
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 |
This file contains hidden or 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
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) | |
} |
This file contains hidden or 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
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