You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
575 B

  1. // Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. package cache
  7. import (
  8. "math/rand"
  9. "testing"
  10. "time"
  11. )
  12. func BenchmarkLRUCache(b *testing.B) {
  13. c := NewCache(NewLRU(10000))
  14. b.SetParallelism(10)
  15. b.RunParallel(func(pb *testing.PB) {
  16. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  17. for pb.Next() {
  18. key := uint64(r.Intn(1000000))
  19. c.Get(0, key, func() (int, Value) {
  20. return 1, key
  21. }).Release()
  22. }
  23. })
  24. }