index_bench_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mvcc
  15. import (
  16. "testing"
  17. "go.uber.org/zap"
  18. )
  19. func BenchmarkIndexCompact1(b *testing.B) { benchmarkIndexCompact(b, 1) }
  20. func BenchmarkIndexCompact100(b *testing.B) { benchmarkIndexCompact(b, 100) }
  21. func BenchmarkIndexCompact10000(b *testing.B) { benchmarkIndexCompact(b, 10000) }
  22. func BenchmarkIndexCompact100000(b *testing.B) { benchmarkIndexCompact(b, 100000) }
  23. func BenchmarkIndexCompact1000000(b *testing.B) { benchmarkIndexCompact(b, 1000000) }
  24. func benchmarkIndexCompact(b *testing.B, size int) {
  25. log := zap.NewNop()
  26. kvindex := newTreeIndex(log)
  27. bytesN := 64
  28. keys := createBytesSlice(bytesN, size)
  29. for i := 1; i < size; i++ {
  30. kvindex.Put(keys[i], revision{main: int64(i), sub: int64(i)})
  31. }
  32. b.ResetTimer()
  33. for i := 1; i < b.N; i++ {
  34. kvindex.Compact(int64(i))
  35. }
  36. }