open/read vs open/mmap vs open/bufio.read on golang.
package main
import (
"fmt"
"log"
"os"
)
func main() {
if len(os.Args) < 2 {
return
}
path := os.Args[1]
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
fi, err := f.Stat()
if err != nil {
log.Fatal(err)
}
buf := make([]byte, fi.Size())
_, err = f.Read(buf)
if err != nil {
log.Fatal(err)
}
cnt := 0
for _, b := range buf {
if b == 0x00 {
cnt++
}
}
f.Close()
fmt.Printf("%s: size=%d cnt=%d\n", path, fi.Size(), cnt);
}