io.Writer.Write()とfmt.Fprintf()のBenchmark

tl;dr 基本的にio.Writer.Write()を使用するのが高速なようです。 result $ go test -bench . -benchmem BenchmarkWrite-4 30000000 48.7 ns/op 16 B/op 1 allocs/op BenchmarkWriteWithBytes-4 500000000 3.95 ns/op 0 B/op 0 allocs/op BenchmarkFprintf-4 20000000 91.5 ns/op 0 B/op 0 allocs/op BenchmarkWriteTo-4 100000000 10.0 ns/op 0 B/op 0 allocs/op BenchmarkWriteWithBufferBytes-4 300000000 4.31 ns/op 0 B/op 0 allocs/op source package main_test import ( "bytes" "fmt" "io" "net/http" "testing" ) var s = "Hello, my world" var bs = []byte(s) var buf = bytes....

2017-09-02 · nasa9084