1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00
This commit is contained in:
2022-05-31 13:47:48 +08:00
parent ebf862e40b
commit 6d39dbb942
8 changed files with 72 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package maps
import (
"fmt"
"sync"
"testing"
"time"
@ -25,3 +26,42 @@ func TestConcurrence(t *testing.T) {
wg.Wait()
}
func TestConcurrenceMapForeach(t *testing.T) {
m := NewConcurrentMap[string, string]()
m.Set("a", "a")
m.ForEach(func(s1, s2 string) bool {
fmt.Println(s1, s2)
return false
})
}
func BenchmarkItor(b *testing.B) {
m := NewHashMap[string, string]().Synchronize()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.Set("a", "b")
for entity := range m.Iter() {
m.Delete(entity.Key)
}
}
})
}
func BenchmarkMap(b *testing.B) {
m := NewHashMap[string, string]().Synchronize()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
m.Set("a", "a")
m.ForEach(func(s1, s2 string) bool {
m.Delete("a")
return false
})
}
})
}