forked from segmentio/go-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_test.go
37 lines (31 loc) · 678 Bytes
/
stats_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
package stats
import "github.com/bmizerany/assert"
import "sync/atomic"
import "testing"
type Statistics struct {
Something int64
}
func TestIncr(t *testing.T) {
stats := New()
stats.Incr("messages")
stats.Incr("messages")
assert.Equal(t, int64(2), stats.Get("messages"))
}
func TestIncrBy(t *testing.T) {
stats := New()
stats.IncrBy("messages", 5)
stats.IncrBy("messages", 10)
assert.Equal(t, int64(15), stats.Get("messages"))
}
func BenchmarkIncr(b *testing.B) {
stats := New()
for i := 0; i < b.N; i++ {
stats.Incr("something")
}
}
func BenchmarkAtomic(b *testing.B) {
var s Statistics
for i := 0; i < b.N; i++ {
atomic.AddInt64(&s.Something, 1)
}
}