parent
c57649e758
commit
28e69d7fb4
57
pmap_test.go
57
pmap_test.go
|
@ -35,6 +35,8 @@ func BenchmarkGet(b *testing.B) {
|
||||||
b.Run("size=100", func(b *testing.B) { benchmarkGet(b, 100) })
|
b.Run("size=100", func(b *testing.B) { benchmarkGet(b, 100) })
|
||||||
b.Run("size=1000", func(b *testing.B) { benchmarkGet(b, 1000) })
|
b.Run("size=1000", func(b *testing.B) { benchmarkGet(b, 1000) })
|
||||||
b.Run("size=10000", func(b *testing.B) { benchmarkGet(b, 10000) })
|
b.Run("size=10000", func(b *testing.B) { benchmarkGet(b, 10000) })
|
||||||
|
//b.Run("size=100000", func(b *testing.B) { benchmarkGet(b, 100000) })
|
||||||
|
//b.Run("size=1000000", func(b *testing.B) { benchmarkGet(b, 1000000) })
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGetAbsent(b *testing.B) {
|
func BenchmarkGetAbsent(b *testing.B) {
|
||||||
|
@ -69,7 +71,7 @@ func benchmarkGet(b *testing.B, numElems int) {
|
||||||
func benchmarkGetAbsent(b *testing.B, numElems int) {
|
func benchmarkGetAbsent(b *testing.B, numElems int) {
|
||||||
p := New(hash)
|
p := New(hash)
|
||||||
for i := range iter(numElems) {
|
for i := range iter(numElems) {
|
||||||
p = p.Set(-i-1, i)
|
p = p.Set(i-numElems, i)
|
||||||
}
|
}
|
||||||
if p.Len() != numElems {
|
if p.Len() != numElems {
|
||||||
b.Fatalf("Len() = %v, want %v", p.Len(), numElems)
|
b.Fatalf("Len() = %v, want %v", p.Len(), numElems)
|
||||||
|
@ -94,6 +96,8 @@ func BenchmarkHmapGet_baseline(b *testing.B) {
|
||||||
b.Run("size=100", func(b *testing.B) { benchmarkHmapGet(b, 100) })
|
b.Run("size=100", func(b *testing.B) { benchmarkHmapGet(b, 100) })
|
||||||
b.Run("size=1000", func(b *testing.B) { benchmarkHmapGet(b, 1000) })
|
b.Run("size=1000", func(b *testing.B) { benchmarkHmapGet(b, 1000) })
|
||||||
b.Run("size=10000", func(b *testing.B) { benchmarkHmapGet(b, 10000) })
|
b.Run("size=10000", func(b *testing.B) { benchmarkHmapGet(b, 10000) })
|
||||||
|
b.Run("size=100000", func(b *testing.B) { benchmarkHmapGet(b, 100000) })
|
||||||
|
b.Run("size=1000000", func(b *testing.B) { benchmarkHmapGet(b, 1000000) })
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkHmapGet(b *testing.B, numElems int) {
|
func benchmarkHmapGet(b *testing.B, numElems int) {
|
||||||
|
@ -117,3 +121,54 @@ func benchmarkHmapGet(b *testing.B, numElems int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkSet(b *testing.B) {
|
||||||
|
b.Run("size=10", func(b *testing.B) { benchmarkSet(b, 10) })
|
||||||
|
b.Run("size=100", func(b *testing.B) { benchmarkSet(b, 100) })
|
||||||
|
b.Run("size=1000", func(b *testing.B) { benchmarkSet(b, 1000) })
|
||||||
|
b.Run("size=10000", func(b *testing.B) { benchmarkSet(b, 10000) })
|
||||||
|
if !testing.Short() {
|
||||||
|
b.Run("size=100000", func(b *testing.B) { benchmarkSet(b, 100000) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkSet(b *testing.B, numElems int) {
|
||||||
|
p := New(hash)
|
||||||
|
for i := range iter(numElems) {
|
||||||
|
p = p.Set(i, i)
|
||||||
|
}
|
||||||
|
if p.Len() != numElems {
|
||||||
|
b.Fatalf("Len() = %v, want %v", p.Len(), numElems)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := range iter(b.N) {
|
||||||
|
k := i + numElems
|
||||||
|
_ = p.Set(k, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkHmapSet_baseline(b *testing.B) {
|
||||||
|
b.Run("size=10", func(b *testing.B) { benchmarkHmapSet(b, 10) })
|
||||||
|
b.Run("size=100", func(b *testing.B) { benchmarkHmapSet(b, 100) })
|
||||||
|
b.Run("size=1000", func(b *testing.B) { benchmarkHmapSet(b, 1000) })
|
||||||
|
b.Run("size=10000", func(b *testing.B) { benchmarkHmapSet(b, 10000) })
|
||||||
|
if !testing.Short() {
|
||||||
|
b.Run("size=100000", func(b *testing.B) { benchmarkHmapSet(b, 100000) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkHmapSet(b *testing.B, numElems int) {
|
||||||
|
h := make(map[int]int)
|
||||||
|
for i := range iter(numElems) {
|
||||||
|
h[i] = i
|
||||||
|
}
|
||||||
|
if len(h) != numElems {
|
||||||
|
b.Fatalf("Len() = %v, want %v", len(h), numElems)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := range iter(b.N) {
|
||||||
|
k := i + numElems
|
||||||
|
h[k] = k
|
||||||
|
delete(h, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue