-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark_test.go
43 lines (38 loc) · 990 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
package fcache
import (
"testing"
)
// go test -run=^^$ -bench=^BenchmarkMemCacheSet$ -benchmem
func BenchmarkMemCacheSet(b *testing.B) {
cache := NewMemCache(100, false)
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Set("key", []byte("value"))
}
}
// go test -run=^^$ -bench=^BenchmarkMemCacheGet$ -benchmem
func BenchmarkMemCacheGet(b *testing.B) {
cache := NewMemCache(100, false)
cache.Set("key", []byte("value"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Get("key")
}
}
// go test -run=^^$ -bench=^BenchmarkDiskCacheSet$ -benchmem
func BenchmarkDiskCacheSet(b *testing.B) {
cache := NewDiskCache(100, false, "./cache")
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Set("key", []byte("value"))
}
}
// go test -run=^^$ -bench=^BenchmarkDiskCacheGet$ -benchmem
func BenchmarkDiskCacheGet(b *testing.B) {
cache := NewDiskCache(100, false, "./cache")
cache.Set("key", []byte("value"))
b.ResetTimer()
for i := 0; i < b.N; i++ {
cache.Get("key")
}
}