mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
map
This commit is contained in:
@ -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
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user