Created
March 27, 2016 10:58
-
-
Save sitano/cbeeb9f990d0b002e0f0 to your computer and use it in GitHub Desktop.
Max active spinning ns/op in go runtime 1.6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// proc_test.s | |
#include "go_asm.h" | |
#include "go_tls.h" | |
#include "funcdata.h" | |
#include "textflag.h" | |
TEXT runtime·ProcYield(SB),NOSPLIT,$0-0 | |
MOVL cycles+0(FP), AX | |
again: | |
PAUSE | |
SUBL $1, AX | |
JNZ again | |
RET | |
// proc.go | |
package runtime | |
func ProcYield(cycles uint32) | |
// proc_test.go | |
package runtime_test | |
const ( | |
active_spin = 4 | |
active_spin_cnt = 30 | |
passive_spin = 1 | |
) | |
func MaxSpin() { | |
for i := 0; i < active_spin; i ++ { | |
runtime.ProcYield(active_spin_cnt) | |
} | |
} | |
func BenchmarkMaxSpin(b *testing.B) { | |
for i := 0; i < b.N; i ++ { | |
MaxSpin() | |
} | |
} | |
// Results | |
// go test -run ! -bench MaxSpin . -v | |
BenchmarkMaxSpin-8 3000000 420 ns/op |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment