-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk.go
More file actions
46 lines (40 loc) · 705 Bytes
/
disk.go
File metadata and controls
46 lines (40 loc) · 705 Bytes
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
package main
import (
"fmt"
"os"
"time"
)
const MB = 1000000
func writeData(s string, inp []byte) {
f, _ := os.Create(s)
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
}()
f.Write([]byte(inp))
f.Sync()
}
func makeData(n int) []byte {
x := make([]byte, n)
for i := 0; i < n; i++ {
x[i] = 1
}
return x
}
func readData(s string, n int) (int, []byte) {
d := make([]byte, n)
f, _ := os.Open(s)
nn, _ := f.Read(d)
return nn, d
}
func main() {
mx := 1000000000
inp := makeData(mx)
st := time.Now()
writeData("output.txt", inp)
d := time.Since(st)
fmt.Println("time taken ", d)
tp := float64(mx) / d.Seconds()
fmt.Printf("through put is %2f MB/s", tp/(MB))
}