mirror of
https://github.com/golang/go.git
synced 2025-11-01 09:10:57 +00:00
suffixarray: add benchmarks for construction
R=gri, jeff CC=golang-dev https://golang.org/cl/5040048
This commit is contained in:
parent
17410d75d0
commit
481e619c50
1 changed files with 24 additions and 0 deletions
|
|
@ -257,6 +257,30 @@ func TestIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Of all possible inputs, the random bytes have the least amount of substring
|
||||||
|
// repetition, and the repeated bytes have the most. For most algorithms,
|
||||||
|
// the running time of every input will be between these two.
|
||||||
|
func benchmarkNew(b *testing.B, random bool) {
|
||||||
|
b.StopTimer()
|
||||||
|
data := make([]byte, 1e6)
|
||||||
|
if random {
|
||||||
|
for i := range data {
|
||||||
|
data[i] = byte(rand.Intn(256))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
New(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkNewIndexRandom(b *testing.B) {
|
||||||
|
benchmarkNew(b, true)
|
||||||
|
}
|
||||||
|
func BenchmarkNewIndexRepeat(b *testing.B) {
|
||||||
|
benchmarkNew(b, false)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkSaveRestore(b *testing.B) {
|
func BenchmarkSaveRestore(b *testing.B) {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
r := rand.New(rand.NewSource(0x5a77a1)) // guarantee always same sequence
|
r := rand.New(rand.NewSource(0x5a77a1)) // guarantee always same sequence
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue