You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
491 B

8 years ago
  1. package benchmarks
  2. import (
  3. "os"
  4. "testing"
  5. . "github.com/tendermint/tmlibs/common"
  6. )
  7. func BenchmarkFileWrite(b *testing.B) {
  8. b.StopTimer()
  9. file, err := os.OpenFile("benchmark_file_write.out",
  10. os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
  11. if err != nil {
  12. b.Error(err)
  13. }
  14. testString := RandStr(200) + "\n"
  15. b.StartTimer()
  16. for i := 0; i < b.N; i++ {
  17. file.Write([]byte(testString))
  18. }
  19. file.Close()
  20. err = os.Remove("benchmark_file_write.out")
  21. if err != nil {
  22. b.Error(err)
  23. }
  24. }