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.

33 lines
588 B

  1. package benchmarks
  2. import (
  3. "os"
  4. "testing"
  5. cmn "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 := cmn.RandStr(200) + "\n"
  15. b.StartTimer()
  16. for i := 0; i < b.N; i++ {
  17. _, err := file.Write([]byte(testString))
  18. if err != nil {
  19. b.Error(err)
  20. }
  21. }
  22. if err := file.Close(); err != nil {
  23. b.Error(err)
  24. }
  25. if err := os.Remove("benchmark_file_write.out"); err != nil {
  26. b.Error(err)
  27. }
  28. }