forked from muesli/cache2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
49 lines (42 loc) · 776 Bytes
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Simple caching library with expiration capabilities
* Copyright (c) 2013-2017, Christian Muehlhaeuser <[email protected]>
*
* For license see LICENSE.txt
*/
package cache2go
import (
"sync"
"sync/atomic"
"testing"
"time"
)
func BenchmarkNotFoundAdd(b *testing.B) {
table := Cache("testNotFoundAdd")
var finish sync.WaitGroup
var added int32
var idle int32
fn := func(id int) {
for i := 0; i < b.N; i++ {
if table.NotFoundAdd(i, 0, i+id) {
atomic.AddInt32(&added, 1)
} else {
atomic.AddInt32(&idle, 1)
}
time.Sleep(0)
}
finish.Done()
}
finish.Add(10)
go fn(0x0000)
go fn(0x1100)
go fn(0x2200)
go fn(0x3300)
go fn(0x4400)
go fn(0x5500)
go fn(0x6600)
go fn(0x7700)
go fn(0x8800)
go fn(0x9900)
finish.Wait()
}