tendermint/benchmarks/os_test.go

30 lines
491 B
Go
Raw Normal View History

2015-12-20 11:37:54 -08:00
package benchmarks
import (
"os"
"testing"
2017-04-21 15:12:54 -07:00
. "github.com/tendermint/tmlibs/common"
2015-12-20 11:37:54 -08:00
)
func BenchmarkFileWrite(b *testing.B) {
b.StopTimer()
file, err := os.OpenFile("benchmark_file_write.out",
os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
b.Error(err)
}
testString := RandStr(200) + "\n"
b.StartTimer()
for i := 0; i < b.N; i++ {
file.Write([]byte(testString))
}
file.Close()
err = os.Remove("benchmark_file_write.out")
if err != nil {
b.Error(err)
}
}