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++ } }) }
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) } }
func BAtomicFind(b *testing.B, sm api.StoredMap) { var k string l := len(UniqKey) finder := func(key string) { sm.Atomic(func(m api.Mapper) { if value, found := m.Find(key); found { _ = value.(string) } }) } b.ReportAllocs() b.SetBytes(2) b.ResetTimer() for i := 0; i < b.N; i++ { k = UniqKey[i%l] finder(k) } }
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) } }