github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/syndtr/goleveldb/leveldb/cache/bench_test.go (about) 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 7 package cache 8 9 import ( 10 "math/rand" 11 "testing" 12 "time" 13 ) 14 15 func BenchmarkLRUCache(b *testing.B) { 16 c := NewCache(NewLRU(10000)) 17 18 b.SetParallelism(10) 19 b.RunParallel(func(pb *testing.PB) { 20 r := rand.New(rand.NewSource(time.Now().UnixNano())) 21 22 for pb.Next() { 23 key := uint64(r.Intn(1000000)) 24 c.Get(0, key, func() (int, Value) { 25 return 1, key 26 }).Release() 27 } 28 }) 29 }