-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
52 lines (49 loc) · 1.14 KB
/
main.go
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
package main
import (
"bufio"
"fmt"
"io"
"os"
"time"
"github.com/Cloud-Foundations/Dominator/lib/format"
"github.com/Cloud-Foundations/Dominator/lib/fsbench"
"github.com/Cloud-Foundations/Dominator/lib/fsrateio"
)
// Benchmark the read speed of the underlying block device for a given file.
func main() {
pathname := "/"
if len(os.Args) == 2 {
pathname = os.Args[1]
}
bytesPerSecond, blocksPerSecond, err := fsbench.GetReadSpeed(pathname)
if err != nil {
fmt.Fprintf(os.Stderr, "Error! %s\n", err)
return
}
ctx := fsrateio.NewReaderContext(bytesPerSecond, blocksPerSecond, 0)
fmt.Println(ctx)
var file *os.File
file, err = os.Open(pathname)
if err != nil {
fmt.Fprintf(os.Stderr, "Error! %s\n", err)
return
}
rd := bufio.NewReader(ctx.NewReader(file))
buffer := make([]byte, 65536)
timeStart := time.Now()
tread := 0
for {
n := 0
n, err = rd.Read(buffer)
if n < 1 && err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "Error! %s\n", err)
return
}
tread += n
}
bytesPerSecond = uint64(float64(tread) / time.Since(timeStart).Seconds())
fmt.Printf("%s/s\n", format.FormatBytes(bytesPerSecond))
}