Skip to content

Instantly share code, notes, and snippets.

@gaurishhs
Last active February 18, 2023 07:26
Show Gist options
  • Save gaurishhs/9acf063dcdaec3aab1caf9e1cb439854 to your computer and use it in GitHub Desktop.
Save gaurishhs/9acf063dcdaec3aab1caf9e1cb439854 to your computer and use it in GitHub Desktop.
Go vs Bun Benchmark
echo "\n\n# Benchmarking Golang"
go build main.go
./main &
PID=$!
sleep 2
bombardier --fasthttp -c 100 -n 10000 http://127.0.0.1:8000/
ps -o pid,ppid,pcpu,pmem,command -p $PID
# Thread count
echo "Threads: $(ps -M $PID | grep -v USER | wc -l)"
kill $PID
echo "\n\n# Benchmarking Bun"
bun run index.ts &
PID=$!
sleep 2
bombardier --fasthttp -c 100 -n 10000 http://127.0.0.1:8000/
ps -o pid,ppid,pcpu,pmem,command -p $PID
# Thread count
echo "Threads: $(ps -M $PID | grep -v USER | wc -l)"
kill $PID
var buffer = new Buffer(1024*1024);
for (var i = 0; i < buffer.length; i++)
buffer[i] = 100;
Bun.serve({
port: 8000,
fetch(req) {
return new Response(buffer, { headers: { 'Content-Type': 'text/plain' } })
}
})
console.log('Server running at http://127.0.0.1:8000/');
package main
import (
"log"
"net/http"
)
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment