-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock_test.go
46 lines (42 loc) · 1 KB
/
lock_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2012 by Christoph Hack <[email protected]>
// All rights reserved. Distributed under the Simplified BSD License.
package goco
import (
"runtime"
"sync"
"testing"
)
func BenchmarkTASLock(b *testing.B) {
procs := runtime.GOMAXPROCS(-1)
lock := new(TASLock)
wg := new(sync.WaitGroup)
wg.Add(procs)
for proc := 0; proc < procs; proc++ {
go func() {
runtime.LockOSThread()
for i := 0; i < b.N; i++ {
lock.Lock()
lock.Unlock()
}
wg.Done()
}()
}
wg.Wait()
}
func BenchmarkTTASLock(b *testing.B) {
procs := runtime.GOMAXPROCS(-1)
lock := new(TTASLock)
wg := new(sync.WaitGroup)
wg.Add(procs)
for proc := 0; proc < procs; proc++ {
go func() {
runtime.LockOSThread()
for i := 0; i < b.N; i++ {
lock.Lock()
lock.Unlock()
}
wg.Done()
}()
}
wg.Wait()
}