From 9b337b72f4f1e2512ac869f8929e8a0759fa0d31 Mon Sep 17 00:00:00 2001 From: sukun Date: Fri, 17 Sep 2021 23:59:29 +0530 Subject: [PATCH] flush write to file call --- .gitignore | 1 + disk.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f47cb20 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.out diff --git a/disk.go b/disk.go index a31d67d..bf05a36 100644 --- a/disk.go +++ b/disk.go @@ -16,6 +16,7 @@ func writeData(s string, inp []byte) { } }() f.Write([]byte(inp)) + f.Sync() } func makeData(n int) []byte { @@ -35,10 +36,11 @@ func readData(s string, n int) (int, []byte) { func main() { mx := 1000000000 + inp := makeData(mx) st := time.Now() - x, _ := readData("output.txt", mx) + writeData("output.txt", inp) d := time.Since(st) - fmt.Println("time taken ", d, x) + fmt.Println("time taken ", d) tp := float64(mx) / d.Seconds() fmt.Printf("through put is %2f MB/s", tp/(MB)) }