Add benchmark for reading files
This commit is contained in:
parent
8be031a3d1
commit
dc11d33a97
@ -2,6 +2,8 @@ package fs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
gorand "math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/datarhei/core/v16/math/rand"
|
||||
@ -60,3 +62,25 @@ func BenchmarkMemRemoveList(b *testing.B) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMemReadFile(b *testing.B) {
|
||||
mem, err := NewMemFilesystem(MemConfig{})
|
||||
require.NoError(b, err)
|
||||
|
||||
nFiles := 1000
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
path := fmt.Sprintf("/%d.dat", i)
|
||||
mem.WriteFile(path, []byte(rand.StringAlphanumeric(2*1024)))
|
||||
}
|
||||
|
||||
r := gorand.New(gorand.NewSource(42))
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
num := r.Intn(nFiles)
|
||||
f := mem.Open("/" + strconv.Itoa(num) + ".dat")
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user