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 15022c4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 59 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,25 @@ 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
BenchmarkCcacheGet
BenchmarkCcacheGet-8 48490944 135.8 ns/op 20 B/op 2 allocs/op
BenchmarkCloudflareGet-8 32122790 183.9 ns/op 18 B/op 1 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
70 changes: 26 additions & 44 deletions bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
theine "github.com/Yiling-J/theine-go"
cloudflare "github.com/cloudflare/golibs/lrucache"
ristretto "github.com/dgraph-io/ristretto"
ccache "github.com/karlseguin/ccache/v3"
otter "github.com/maypok86/otter"
ecache "github.com/orca-zhang/ecache"
phuslu "github.com/phuslu/lru"
Expand Down Expand Up @@ -39,36 +38,16 @@ 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) {
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)
}
}
})
}

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) {
expires := time.Now().Add(time.Hour)
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, expires)
}
}
})
Expand All @@ -79,16 +58,15 @@ func BenchmarkEcacheGet(b *testing.B) {
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 +75,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 +88,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 +109,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 +130,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 +151,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
2 changes: 1 addition & 1 deletion bench/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/Yiling-J/theine-go v0.3.1
github.com/cloudflare/golibs v0.0.0-20210909181612-21743d7dd02a
github.com/dgraph-io/ristretto v0.1.1
github.com/karlseguin/ccache/v3 v3.0.5
github.com/maypok86/otter v0.0.0-20231222143008-a9479c80c78a
github.com/orca-zhang/ecache v1.1.1
github.com/phuslu/lru v0.0.0-00010101000000-000000000000
Expand All @@ -22,6 +21,7 @@ require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/ncw/directio v1.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/sys v0.8.0 // indirect
)
Expand Down
6 changes: 2 additions & 4 deletions bench/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/karlseguin/ccache/v3 v3.0.5 h1:hFX25+fxzNjsRlREYsoGNa2LoVEw5mPF8wkWq/UnevQ=
github.com/karlseguin/ccache/v3 v3.0.5/go.mod h1:qxC372+Qn+IBj8Pe3KvGjHPj0sWwEF7AeZVhsNPZ6uY=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down Expand Up @@ -75,8 +73,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
Expand Down

0 comments on commit 15022c4

Please sign in to comment.