mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 01:24:04 -08:00
7e6a03fbf9
Change-Id: I8615e8816e79ef0882e123163ee590c739b79d12
46 lines
920 B
Go
46 lines
920 B
Go
package local
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
)
|
|
|
|
func BenchmarkFingerprintLockerParallel(b *testing.B) {
|
|
numGoroutines := 10
|
|
numFingerprints := 10
|
|
numLockOps := b.N
|
|
locker := newFingerprintLocker(100)
|
|
|
|
wg := sync.WaitGroup{}
|
|
b.ResetTimer()
|
|
for i := 0; i < numGoroutines; i++ {
|
|
wg.Add(1)
|
|
go func(i int) {
|
|
for j := 0; j < numLockOps; j++ {
|
|
fp1 := clientmodel.Fingerprint(j % numFingerprints)
|
|
fp2 := clientmodel.Fingerprint(j%numFingerprints + numFingerprints)
|
|
locker.Lock(fp1)
|
|
locker.Lock(fp2)
|
|
locker.Unlock(fp2)
|
|
locker.Unlock(fp1)
|
|
}
|
|
wg.Done()
|
|
}(i)
|
|
}
|
|
wg.Wait()
|
|
}
|
|
|
|
func BenchmarkFingerprintLockerSerial(b *testing.B) {
|
|
numFingerprints := 10
|
|
locker := newFingerprintLocker(100)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
fp := clientmodel.Fingerprint(i % numFingerprints)
|
|
locker.Lock(fp)
|
|
locker.Unlock(fp)
|
|
}
|
|
}
|