|
@ -5,12 +5,13 @@ import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"math/rand" |
|
|
"math/rand" |
|
|
"os" |
|
|
"os" |
|
|
|
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
minSize = flag.Int("minSize", 1024, "min file size") |
|
|
minSize = flag.Int("minSize", 1024, "min file size") |
|
|
maxSize = flag.Int("maxSize", 10*1024*1024, "max file size") |
|
|
|
|
|
fileCount = flag.Int("fileCount", 1, "number of files to write") |
|
|
|
|
|
|
|
|
maxSize = flag.Int("maxSize", 3*1024*1024, "max file size") |
|
|
|
|
|
fileCount = flag.Int("n", 1, "number of files to write") |
|
|
blockSize = flag.Int("blockSizeKB", 4, "write block size") |
|
|
blockSize = flag.Int("blockSizeKB", 4, "write block size") |
|
|
toDir = flag.String("dir", ".", "destination directory") |
|
|
toDir = flag.String("dir", ".", "destination directory") |
|
|
) |
|
|
) |
|
@ -25,7 +26,7 @@ func main() { |
|
|
|
|
|
|
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
block := make([]byte, *blockSize) |
|
|
|
|
|
|
|
|
block := make([]byte, *blockSize*1024) |
|
|
|
|
|
|
|
|
for i := 0; i < *fileCount; i++ { |
|
|
for i := 0; i < *fileCount; i++ { |
|
|
|
|
|
|
|
@ -33,17 +34,21 @@ func main() { |
|
|
check(err) |
|
|
check(err) |
|
|
|
|
|
|
|
|
fileSize := *minSize + rand.Intn(*maxSize-*minSize) |
|
|
fileSize := *minSize + rand.Intn(*maxSize-*minSize) |
|
|
|
|
|
startTime := time.Now() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("write %s %d bytes: ", f.Name(), fileSize) |
|
|
|
|
|
|
|
|
for x := 0; x < fileSize; { |
|
|
for x := 0; x < fileSize; { |
|
|
rand.Read(block) |
|
|
rand.Read(block) |
|
|
_, err = f.Write(block) |
|
|
_, err = f.Write(block) |
|
|
check(err) |
|
|
check(err) |
|
|
x += *blockSize |
|
|
|
|
|
|
|
|
x += len(block) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = f.Close() |
|
|
err = f.Close() |
|
|
check(err) |
|
|
check(err) |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%.02f MB/sec\n", float64(fileSize)*float64(time.Second)/float64(time.Now().Sub(startTime)*1024*1024)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |