Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <kpango@vdaas.org>
  • Loading branch information
kpango committed Nov 18, 2022
1 parent 9c9c77c commit 0d00e17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 2 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
alias:
default: &default
working_directory: /go/src/github.com/kpango/gache
docker:
- image: circleci/golang:1.17
- image: circleci/go:1.19
environment:
GOPATH: "/go"
GO111MODULE: "on"
REPO_NAME: "kpango"
IMAGE_NAME: "gache"
GITHUB_API: "https://api.github.com/"
DOCKER_USER: "kpango"
setup_remote_docker: &setup_remote_docker
version: 19.03.4
version: 20.10.18
docker_layer_caching: true

version: 2
Expand Down
4 changes: 2 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
return true
})

file, err := os.OpenFile("/tmp/gache-sample.gdb", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0755)
file, err := os.OpenFile("/tmp/gache-sample.gdb", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o755)
if err != nil {
glg.Error(err)
return
Expand All @@ -55,7 +55,7 @@ func main() {
file.Close()

gcn := gache.New[any]().SetDefaultExpire(time.Minute)
file, err = os.OpenFile("/tmp/gache-sample.gdb", os.O_RDONLY, 0755)
file, err = os.OpenFile("/tmp/gache-sample.gdb", os.O_RDONLY, 0o755)
if err != nil {
glg.Error(err)
return
Expand Down
10 changes: 9 additions & 1 deletion gache_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func randStr(n int) string {
func benchmark(b *testing.B, data map[string]string,
t time.Duration,
set func(string, string, time.Duration),
get func(string)) {
get func(string),
) {
b.Helper()
b.SetParallelism(parallelism)
b.ReportAllocs()
Expand All @@ -107,24 +108,28 @@ func BenchmarkDefaultMapSetSmallDataNoTTL(b *testing.B) {
func(k, v string, t time.Duration) { m.Set(k, v) },
func(k string) { m.Get(k) })
}

func BenchmarkDefaultMapSetBigDataNoTTL(b *testing.B) {
m := NewDefault()
benchmark(b, bigData, NoTTL,
func(k, v string, t time.Duration) { m.Set(k, v) },
func(k string) { m.Get(k) })
}

func BenchmarkSyncMapSetSmallDataNoTTL(b *testing.B) {
var m sync.Map
benchmark(b, smallData, NoTTL,
func(k, v string, t time.Duration) { m.Store(k, v) },
func(k string) { m.Load(k) })
}

func BenchmarkSyncMapSetBigDataNoTTL(b *testing.B) {
var m sync.Map
benchmark(b, bigData, NoTTL,
func(k, v string, t time.Duration) { m.Store(k, v) },
func(k string) { m.Load(k) })
}

func BenchmarkGacheSetSmallDataNoTTL(b *testing.B) {
g := New[string](
WithDefaultExpiration[string](NoTTL),
Expand All @@ -133,6 +138,7 @@ func BenchmarkGacheSetSmallDataNoTTL(b *testing.B) {
func(k, v string, t time.Duration) { g.Set(k, v) },
func(k string) { g.Get(k) })
}

func BenchmarkGacheSetSmallDataWithTTL(b *testing.B) {
g := New[string](
WithDefaultExpiration[string](ttl),
Expand All @@ -141,6 +147,7 @@ func BenchmarkGacheSetSmallDataWithTTL(b *testing.B) {
func(k, v string, t time.Duration) { g.SetWithExpire(k, v, t) },
func(k string) { g.Get(k) })
}

func BenchmarkGacheSetBigDataNoTTL(b *testing.B) {
g := New[string](
WithDefaultExpiration[string](NoTTL),
Expand All @@ -149,6 +156,7 @@ func BenchmarkGacheSetBigDataNoTTL(b *testing.B) {
func(k, v string, t time.Duration) { g.Set(k, v) },
func(k string) { g.Get(k) })
}

func BenchmarkGacheSetBigDataWithTTL(b *testing.B) {
g := New[string](
WithDefaultExpiration[string](ttl),
Expand Down

0 comments on commit 0d00e17

Please sign in to comment.