Skip to content

Commit

Permalink
benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
parMaster committed Jul 13, 2023
1 parent 46b8afa commit 13b7e70
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ go func() {

See the [examples](https://github.com/parMaster/mcache/tree/main/examples) directory for more examples.

## Benchmarks
```shell
Running tool: /usr/local/go/bin/go test -benchmem -run=^$ -coverprofile=/tmp/vscode-gopk5hiw/go-code-cover -bench . github.com/parMaster/mcache

goos: linux
goarch: amd64
pkg: github.com/parMaster/mcache
cpu: Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
BenchmarkWrite-4 1797061 815.2 ns/op 247 B/op 3 allocs/op
BenchmarkRead-4 4516329 260.7 ns/op 48 B/op 3 allocs/op
BenchmarkRWD-4 1761019 686.6 ns/op 56 B/op 6 allocs/op
PASS
github.com/parMaster/mcache coverage: 83.0% of statements
ok github.com/parMaster/mcache 7.190s
```

## Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
Expand Down
38 changes: 38 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mcache

import (
"fmt"
"testing"
)

var mcache *Cache

// BenchmarkWrite
func BenchmarkWrite(b *testing.B) {
mcache = NewCache()

b.ResetTimer()
for i := 0; i < b.N; i++ {
mcache.Set(fmt.Sprintf("%d", i), i, int64(i))
}
b.StopTimer()
mcache.Cleanup()
}

// BenchmarkRead
func BenchmarkRead(b *testing.B) {
for i := 0; i < b.N; i++ {
mcache.Get(fmt.Sprintf("%d", i))
}
mcache.Clear()
}

// BenchmarkRW
func BenchmarkRWD(b *testing.B) {
for i := 0; i < b.N; i++ {
mcache.Set(fmt.Sprintf("%d", i), i, int64(i))
mcache.Get(fmt.Sprintf("%d", i))
mcache.Del(fmt.Sprintf("%d", i))
}
mcache.Clear()
}

0 comments on commit 13b7e70

Please sign in to comment.