Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMap为啥性能比标准库的低呢?是我的测试方式有问题吗 #12

Open
pakano opened this issue Mar 10, 2023 · 1 comment
Open

Comments

@pakano
Copy link

pakano commented Mar 10, 2023

`package main

import (
"math/rand"
"strconv"
"sync"
"testing"

"github.com/heiyeluren/xds"
xmap "github.com/heiyeluren/xds/xmap"
xmm "github.com/heiyeluren/xmm"

)

var keys = make([]string, 10000000)

func init() {
for i := 0; i < 10000000; i++ {
keys[i] = strconv.Itoa(rand.Int())
}
}

// 1000000000
func BenchmarkCHM_Put(b *testing.B) {
f := &xmm.Factory{}
mm, err := f.CreateMemory(0.75)
if err != nil {
b.Fatal(err)
}
chm, err := xmap.NewConcurrentHashMap(mm, 16, 2, 8, xds.String, xds.String)
if err != nil {
b.Fatal(err)
}

length := len(keys)
b.ResetTimer()
for i := 0; i < b.N; i++ {
	key := keys[rand.Int()%length]
	if err := chm.Put(key, key); err != nil {
		b.Error(err)
	}
}

}

func BenchmarkStdmap(b *testing.B) {
m := make(map[string]string)

length := len(keys)
b.ResetTimer()
for i := 0; i < b.N; i++ {
	key := keys[rand.Int()%length]
	m[key] = key
}

}

func BenchmarkSyncmap(b *testing.B) {
m := sync.Map{}

length := len(keys)
b.ResetTimer()
for i := 0; i < b.N; i++ {
	key := keys[rand.Int()%length]
	m.Store(key, key)
}

}
`

image

@heiyeluren
Copy link
Owner

I'm not sure if it's due to device or Golang version issues. I suggest you run the built-in performance testing program first. Currently, the agreed upon performance value is based on 20% write and 80% read scenarios. At present, some test codes can refer to: https://github.com/heiyeluren/xds/blob/main/xmap/map_test.go

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants