I am trying to profile my go library to find out what is the reason that in C ++ is going much slower than the same.
I have a simple test
func BenchmarkFile(t *testing.B) { tmpFile, err := ioutil.TempFile("", TMP_FILE_PREFIX) fw, err := NewFile(tmpFile.Name()) text := []byte("testing") for i := 0; i < bN; i++ { _, err = fw.Write(text) } fw.Close() }
NewFile returns my custom Writer, which encodes the data in our binary representation, even compresses it and writes it to the file system.
Running go test -bench . -memprofile mem.out -cpuprofile cpu.out
go test -bench . -memprofile mem.out -cpuprofile cpu.out
I get
PASS BenchmarkFile-16 2000000000 0.20 ns/op ok .../writer/iowriter 9.074s
How to analyze it
# go tool pprof cpu.out Entering interactive mode (type "help" for commands) (pprof) top10 930ms of 930ms total ( 100%) flat flat% sum% cum cum% 930ms 100% 100% 930ms 100% (pprof)
I even try to write an example.go application that my writer uses and add pprof.StartCPUProfile(f)
as shown in http://blog.golang.org/profiling-go-programs , but with the same result.
What am I doing wrong, and how can I determine what is the bottleneck of my library? Thank you in advance
source share