Пример #1
0
func BenchmarkLSemAcq(b *testing.B) {
	s := semaphore.NewLS(1)
	for i := 0; i < b.N; i++ {
		s.Acquire()
		s.Release()
	}
}
Пример #2
0
func BenchmarkLSemLoop5(b *testing.B) {
	for i := 0; i < b.N; i++ {
		s := semaphore.NewLS(5)
		go s.Stop()
		for s.Acquire() {
		}
	}
}
Пример #3
0
func BenchmarkLSemAcqStop(b *testing.B) {
	for i := 0; i < b.N; i++ {
		s := semaphore.NewLS(1)
		s.Acquire()
		go s.Stop()
		s.Acquire()
	}
}
Пример #4
0
func BenchmarkLSemSleep(b *testing.B) {
	s := semaphore.NewLS(1)
	s.Acquire()
	for i := 0; i < b.N; i++ {
		go func() {
			time.Sleep(5 * time.Nanosecond)
			s.Release()
		}()
		s.Acquire()
	}
}
Пример #5
0
func BenchmarkLSemWait(b *testing.B) {
	for i := 0; i < b.N; i++ {
		s := semaphore.NewLS(10)

		var wg sync.WaitGroup
		wg.Add(100)
		for j := 0; j < 100; j++ {
			go func() {
				defer wg.Done()
				for s.Acquire() {
					time.Sleep(1 * time.Nanosecond)
					s.Release()
				}
			}()
		}
		time.Sleep(100 * time.Nanosecond)
		s.Stop()
		wg.Wait()
	}
}