1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright 2017 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// readbench is a benchmark helper for measuring throughput on
// single-file reads out of a FUSE filesystem.
package main
import (
"flag"
"fmt"
"log"
"os"
"time"
)
func gulp(fn string, bs int) (int, error) {
f, err := os.Open(fn)
if err != nil {
return 0, err
}
defer f.Close()
var tot int
buf := make([]byte, bs)
for {
n, _ := f.Read(buf[:])
tot += n
if n < len(buf) {
break
}
}
return tot, nil
}
func main() {
bs := flag.Int("bs", 32, "blocksize in kb")
mbLimit := flag.Int("limit", 1000, "amount of data to read in mb")
flag.Parse()
if len(flag.Args()) < 1 {
log.Fatal("readbench [-bs BLOCKSIZE -limit SIZE] file")
}
blocksize := *bs * 1024
totMB := 0.0
var totDT time.Duration
for totMB < float64(*mbLimit) {
t := time.Now()
n, err := gulp(flag.Arg(0), blocksize)
if err != nil {
log.Fatal(err)
}
dt := time.Now().Sub(t)
mb := float64(n) / (1 << 20)
totMB += mb
totDT += dt
}
fmt.Printf("block size %d kb: %.1f MB in %v: %.2f MBs/s\n", *bs, totMB, totDT, totMB/float64(totDT)*1e9)
}
|