mirror of
https://github.com/golang/go
synced 2024-11-23 05:20:11 -07:00
runtime: refactor Syscall benchmark
And add a benchmark where #goroutines>GOMAXPROCS, because it's the most interesting case. Current results on darwin/amd64, Intel Core 2 Duo 2.13 GHz, 2 cores: BenchmarkSyscall 100000000 56.0 ns/op BenchmarkSyscall-2 50000000 57.2 ns/op BenchmarkSyscallWork 10000000 635 ns/op BenchmarkSyscallWork-2 10000000 315 ns/op BenchmarkSyscallExcess 1000000 2698 ns/op BenchmarkSyscallExcess-2 5000000 1192 ns/op BenchmarkSyscallExcessWork 1000000 2832 ns/op BenchmarkSyscallExcessWork-2 2000000 1966 ns/op R=golang-dev, r CC=golang-dev https://golang.org/cl/7415044
This commit is contained in:
parent
72b09bd7ae
commit
38d4d3c66a
@ -152,31 +152,24 @@ func BenchmarkStackGrowthDeep(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSyscall(b *testing.B) {
|
func BenchmarkSyscall(b *testing.B) {
|
||||||
const CallsPerSched = 1000
|
benchmarkSyscall(b, 0, 1)
|
||||||
procs := runtime.GOMAXPROCS(-1)
|
|
||||||
N := int32(b.N / CallsPerSched)
|
|
||||||
c := make(chan bool, procs)
|
|
||||||
for p := 0; p < procs; p++ {
|
|
||||||
go func() {
|
|
||||||
for atomic.AddInt32(&N, -1) >= 0 {
|
|
||||||
runtime.Gosched()
|
|
||||||
for g := 0; g < CallsPerSched; g++ {
|
|
||||||
runtime.Entersyscall()
|
|
||||||
runtime.Exitsyscall()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c <- true
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
for p := 0; p < procs; p++ {
|
|
||||||
<-c
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkSyscallWork(b *testing.B) {
|
func BenchmarkSyscallWork(b *testing.B) {
|
||||||
|
benchmarkSyscall(b, 100, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSyscallExcess(b *testing.B) {
|
||||||
|
benchmarkSyscall(b, 0, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkSyscallExcessWork(b *testing.B) {
|
||||||
|
benchmarkSyscall(b, 100, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkSyscall(b *testing.B, work, excess int) {
|
||||||
const CallsPerSched = 1000
|
const CallsPerSched = 1000
|
||||||
const LocalWork = 100
|
procs := runtime.GOMAXPROCS(-1) * excess
|
||||||
procs := runtime.GOMAXPROCS(-1)
|
|
||||||
N := int32(b.N / CallsPerSched)
|
N := int32(b.N / CallsPerSched)
|
||||||
c := make(chan bool, procs)
|
c := make(chan bool, procs)
|
||||||
for p := 0; p < procs; p++ {
|
for p := 0; p < procs; p++ {
|
||||||
@ -186,7 +179,7 @@ func BenchmarkSyscallWork(b *testing.B) {
|
|||||||
runtime.Gosched()
|
runtime.Gosched()
|
||||||
for g := 0; g < CallsPerSched; g++ {
|
for g := 0; g < CallsPerSched; g++ {
|
||||||
runtime.Entersyscall()
|
runtime.Entersyscall()
|
||||||
for i := 0; i < LocalWork; i++ {
|
for i := 0; i < work; i++ {
|
||||||
foo *= 2
|
foo *= 2
|
||||||
foo /= 2
|
foo /= 2
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user