Пример #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++
		}
	})
}
Пример #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)
		})
	}
}
Пример #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)
	}
}
Пример #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)
		}
	}
}
Пример #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)
		})
	}
}
Пример #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)
			}
		})
	}
}
Пример #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++
		}
	})
}
Пример #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++
		}
	})
}
Пример #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)
	}
}
Пример #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++
		}
	})
}
Пример #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)
	}
}
Пример #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++
		}
	})
}
Пример #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)
	}
}
Пример #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++
		}
	})
}
Пример #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
	})
}
Пример #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
	})
}