Add benchmark for reading files

This commit is contained in:
Ingo Oppermann 2023-08-03 09:38:36 +03:00
parent 8be031a3d1
commit dc11d33a97
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E

View File

@ -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()
}
}