mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Dont use randomised data for benchmarks
Use a fixed seed for repeatability of the benchmarks
This commit is contained in:
@@ -56,22 +56,22 @@ func (n node) Info() (fs.FileInfo, error) {
|
|||||||
return nil, fmt.Errorf("Info() not implemented")
|
return nil, fmt.Errorf("Info() not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func random_name() string {
|
func random_name(r *rand.Rand) string {
|
||||||
length := 3 + rand.Intn(23)
|
length := 3 + r.Intn(23)
|
||||||
bytes := make([]byte, length)
|
bytes := make([]byte, length)
|
||||||
for i := range length {
|
for i := range length {
|
||||||
// Printable ASCII range: 32 (space) to 126 (~)
|
bytes[i] = byte(r.Intn(26) + 'a')
|
||||||
bytes[i] = byte(rand.Intn(26) + 'a')
|
|
||||||
}
|
}
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) generate_random_tree(depth, breadth int) {
|
func (n *node) generate_random_tree(depth, breadth int) {
|
||||||
|
r := rand.New(rand.NewSource(111))
|
||||||
n.children = make(map[string]*node)
|
n.children = make(map[string]*node)
|
||||||
for range breadth {
|
for range breadth {
|
||||||
c := &node{name: random_name()}
|
c := &node{name: random_name(r)}
|
||||||
n.children[c.name] = c
|
n.children[c.name] = c
|
||||||
if depth > 0 && rand.Intn(10) < 3 {
|
if depth > 0 && r.Intn(10) < 3 {
|
||||||
c.generate_random_tree(depth-1, breadth)
|
c.generate_random_tree(depth-1, breadth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,5 +136,5 @@ func BenchmarkFileNameScoringWithoutQuery(b *testing.B) {
|
|||||||
// To run this benchmark with profiling use:
|
// To run this benchmark with profiling use:
|
||||||
// go test -bench=FileNameScoringWithQuery -benchmem -cpuprofile=/tmp/cpu.prof -memprofile=/tmp/mem.prof github.com/kovidgoyal/kitty/kittens/choose_files -o /tmp/cfexe
|
// go test -bench=FileNameScoringWithQuery -benchmem -cpuprofile=/tmp/cpu.prof -memprofile=/tmp/mem.prof github.com/kovidgoyal/kitty/kittens/choose_files -o /tmp/cfexe
|
||||||
func BenchmarkFileNameScoringWithQuery(b *testing.B) {
|
func BenchmarkFileNameScoringWithQuery(b *testing.B) {
|
||||||
run_scoring(b, 5, 30, "abc")
|
run_scoring(b, 5, 20, "abc")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user