Skip to content

Commit

Permalink
run bench test with 75% reads 25% writes
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Jan 2, 2024
1 parent fefd6a9 commit b31dffe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,27 @@ func main() {

### Benchmarks

A Performance result on keysize=16, cachesize=1000000, parallelism=32. Check [actions][actions] for more results and details.
A Performance result on keysize=16, cachesize=1000000, parallelism=32 with Read(75%)/Write(25%). Check [actions][actions] for more results and details.
```
goos: linux
goarch: amd64
cpu: AMD EPYC 7763 64-Core Processor
BenchmarkCloudflareGet
BenchmarkCloudflareGet-8 43232113 145.9 ns/op 16 B/op 1 allocs/op
BenchmarkCloudflareGet-8 32122790 183.9 ns/op 18 B/op 1 allocs/op
BenchmarkCcacheGet
BenchmarkCcacheGet-8 48490944 135.8 ns/op 20 B/op 2 allocs/op
BenchmarkCcacheGet-8 20696571 313.0 ns/op 48 B/op 2 allocs/op
BenchmarkEcacheGet
BenchmarkEcacheGet-8 51344246 115.7 ns/op 0 B/op 0 allocs/op
BenchmarkEcacheGet-8 49922084 120.0 ns/op 5 B/op 0 allocs/op
BenchmarkRistrettoGet
BenchmarkRistrettoGet-8 56852104 103.4 ns/op 16 B/op 1 allocs/op
BenchmarkRistrettoGet-8 33818906 195.6 ns/op 41 B/op 1 allocs/op
BenchmarkTheineGet
BenchmarkTheineGet-8 51490969 108.8 ns/op 0 B/op 0 allocs/op
BenchmarkTheineGet-8 29022984 208.9 ns/op 0 B/op 0 allocs/op
BenchmarkOtterGet
BenchmarkOtterGet-8 75847165 74.34 ns/op 0 B/op 0 allocs/op
BenchmarkOtterGet-8 71440144 85.35 ns/op 0 B/op 0 allocs/op
BenchmarkPhusluGet
BenchmarkPhusluGet-8 72334320 87.05 ns/op 0 B/op 0 allocs/op
BenchmarkPhusluGet-8 60555633 98.51 ns/op 0 B/op 0 allocs/op
PASS
ok command-line-arguments 58.332s
ok command-line-arguments 61.404s
```

[godoc-img]: http://img.shields.io/badge/godoc-reference-blue.svg
Expand Down
60 changes: 30 additions & 30 deletions bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,52 @@ func BenchmarkCloudflareGet(b *testing.B) {
for i := 0; i < cachesize/2; i++ {
cache.Set(keymap[i], i, time.Now().Add(time.Hour))
}

b.SetParallelism(parallelism)
b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {
expires := time.Now().Add(time.Hour)
for pb.Next() {
i := int(fastrandn(cachesize))
v, ok := cache.Get(keymap[i])
if ok && v.(int) != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
cache.Get(keymap[i])
} else {
cache.Set(keymap[i], i, expires)
}
}
})
}

func BenchmarkCcacheGet(b *testing.B) {
cache := ccache.New(ccache.Configure[int]().MaxSize(cachesize))
for i := 0; i < cachesize/2; i++ {
cache.Set(keymap[i], i, time.Hour)
}

b.SetParallelism(parallelism)
b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := int(fastrandn(cachesize))
v := cache.Get(keymap[i])
if v != nil && v.Value() != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
cache.Get(keymap[i])
} else {
cache.Set(keymap[i], i, time.Hour)
}
}
})
}

func BenchmarkEcacheGet(b *testing.B) {
cache := ecache.NewLRUCache(1024, cachesize/1024, time.Hour)
for i := 0; i < cachesize/2; i++ {
cache.Put(keymap[i], i)
}

b.SetParallelism(parallelism)
b.ResetTimer()

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := int(fastrandn(cachesize))
v, ok := cache.Get(keymap[i])
if ok && v != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
cache.Get(keymap[i])
} else {
cache.Put(keymap[i], i)
}
}
})
Expand All @@ -97,7 +93,7 @@ func BenchmarkEcacheGet(b *testing.B) {
func BenchmarkRistrettoGet(b *testing.B) {
cache, _ := ristretto.NewCache(&ristretto.Config{
NumCounters: cachesize, // number of keys to track frequency of (10M).
MaxCost: 1 << 30, // maximum cost of cache (1GB).
MaxCost: 2 << 30, // maximum cost of cache (2GB).
BufferItems: 64, // number of keys per Get buffer.
})
for i := 0; i < cachesize/2; i++ {
Expand All @@ -110,9 +106,10 @@ func BenchmarkRistrettoGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := int(fastrandn(cachesize))
v, ok := cache.Get(keymap[i])
if ok && v != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
cache.Get(keymap[i])
} else {
cache.SetWithTTL(keymap[i], i, 1, time.Hour)
}
}
})
Expand All @@ -130,9 +127,10 @@ func BenchmarkTheineGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := int(fastrandn(cachesize))
v, ok := cache.Get(keymap[i])
if ok && v != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
_, _ = cache.Get(keymap[i])
} else {
_ = cache.SetWithTTL(keymap[i], i, 1, time.Hour)
}
}
})
Expand All @@ -150,9 +148,10 @@ func BenchmarkOtterGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := int(fastrandn(cachesize))
v, ok := cache.Get(keymap[i])
if ok && v != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
_, _ = cache.Get(keymap[i])
} else {
cache.SetWithTTL(keymap[i], i, time.Hour)
}
}
})
Expand All @@ -170,9 +169,10 @@ func BenchmarkPhusluGet(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
i := int(fastrandn(cachesize))
v, ok := cache.Get(keymap[i])
if ok && v != i {
b.Fatalf("get %v from cache want %v, got %v", keymap[i], i, v)
if i >= cachesize/4 {
_, _ = cache.Get(keymap[i])
} else {
cache.SetWithTTL(keymap[i], i, time.Hour)
}
}
})
Expand Down

0 comments on commit b31dffe

Please sign in to comment.