Beispiel #1
0
func BThreadsAtomicComplex(b *testing.B, sm api.StoredMap) {
	l := len(UniqKey)
	inserter := func(key string) {
		sm.Atomic(func(m api.Mapper) {
			if value, found := m.Find(key); found {
				_ = value.(string)
				return
			}
			m.SetKey(key)
			m.Update(key)
		})
	}
	b.SetParallelism(CntBenchWorks)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var k string
		var i int
		for pb.Next() {
			k = UniqKey[i%l]
			inserter(k)
			i++
		}
	})
}
Beispiel #2
0
func BEachFullCicle(b *testing.B, sm api.StoredMap) {
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		sm.Each(func(m api.Mapper) {
			_ = m.Value().(string)
		})
	}
}
Beispiel #3
0
func BInsert(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		sm.Insert(k, k)
	}
}
Beispiel #4
0
func BFind(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		if value, found := sm.Find(k); found {
			_ = value.(string)
		}
	}
}
Beispiel #5
0
func BAtomicWaitUpdate(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		sm.AtomicWait(func(m api.Mapper) {
			m.SetKey(k)
			m.Update(k)
		})
	}
}
Beispiel #6
0
func BAtomicWaitFind(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		sm.AtomicWait(func(m api.Mapper) {
			if value, found := m.Find(k); found {
				_ = value.(string)
			}
		})
	}
}
Beispiel #7
0
func BThreadsDelete(b *testing.B, sm api.StoredMap) {
	l := len(UniqKey)
	b.SetParallelism(CntBenchWorks)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var k string
		var i int
		for pb.Next() {
			k = UniqKey[i%l]
			sm.Delete(k)
			i++
		}
	})
}
Beispiel #8
0
func BThreadsEachShort(b *testing.B, sm api.StoredMap) {
	b.SetParallelism(CntBenchWorks)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var i int
		for pb.Next() {
			sm.Each(func(m api.Mapper) {
				_ = m.Value().(string)
				m.Stop()
			})
			i++
		}
	})
}
Beispiel #9
0
func BAtomicUpdate(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	inserter := func(key string) {
		sm.Atomic(func(m api.Mapper) {
			m.SetKey(key)
			m.Update(key)
		})
	}
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		inserter(k)
	}
}
Beispiel #10
0
func BThreadsFind(b *testing.B, sm api.StoredMap) {
	l := len(UniqKey)
	b.SetParallelism(CntBenchWorks)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var k string
		var i int
		for pb.Next() {
			k = UniqKey[i%l]
			if value, found := sm.Find(k); found {
				_ = value.(string)
			}
			i++
		}
	})
}
Beispiel #11
0
func BUpdate(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	updater := func(key string) {
		sm.Update(key, func(value interface{}, found bool) interface{} {
			if found {
				_ = value.(string)
			}
			return key
		})
	}
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		updater(k)
	}
}
Beispiel #12
0
func BThreadsAtomicWaitUpdate(b *testing.B, sm api.StoredMap) {
	l := len(UniqKey)
	b.SetParallelism(CntBenchWorks)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var k string
		var i int
		for pb.Next() {
			k = UniqKey[i%l]
			sm.AtomicWait(func(m api.Mapper) {
				m.SetKey(k)
				m.Update(k)
			})
			i++
		}
	})
}
Beispiel #13
0
func BAtomicComplex(b *testing.B, sm api.StoredMap) {
	var k string
	l := len(UniqKey)
	inserter := func(key string) {
		sm.Atomic(func(m api.Mapper) {
			if value, found := m.Find(key); found {
				_ = value.(string)
				return
			}
			m.SetKey(key)
			m.Update(key)
		})
	}
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		k = UniqKey[i%l]
		inserter(k)
	}
}
Beispiel #14
0
func BThreadsUpdate(b *testing.B, sm api.StoredMap) {
	l := len(UniqKey)
	updater := func(key string) {
		sm.Update(key, func(value interface{}, found bool) interface{} {
			if found {
				_ = value.(string)
			}
			return key
		})
	}
	b.SetParallelism(CntBenchWorks)
	b.ReportAllocs()
	b.SetBytes(2)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		var k string
		var i int
		for pb.Next() {
			k = UniqKey[i%l]
			updater(k)
			i++
		}
	})
}
Beispiel #15
0
func testUpdate(sm api.StoredMap, t *test.Item, f func(string, bool)) {
	sm.Update(t.K, func(value interface{}, found bool) interface{} {
		f(t.K, found)
		return t.V
	})
}
Beispiel #16
0
func update(sm api.StoredMap, t *test.Item) {
	sm.Update(t.K, func(value interface{}, found bool) interface{} {
		t.Done <- t
		return t.V
	})
}