index_bench_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2016 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. "fmt"
  17. "testing"
  18. )
  19. func BenchmarkIndexRestore(b *testing.B) {
  20. var (
  21. keys = make([][]byte, b.N)
  22. createds = make([]revision, b.N)
  23. modifieds = make([]revision, b.N)
  24. ver int64 = 1
  25. )
  26. for i := 0; i < b.N; i++ {
  27. keys[i] = []byte(fmt.Sprintf("foo%d", i))
  28. createds[i] = revision{int64(i), 0}
  29. modifieds[i] = revision{int64(i), 1}
  30. }
  31. kvindex := newTreeIndex()
  32. b.ResetTimer()
  33. for i := 0; i < b.N; i++ {
  34. kvindex.Restore(keys[i], createds[i], modifieds[i], ver)
  35. }
  36. }