Skip to content

Instantly share code, notes, and snippets.

@sitano
Created March 27, 2016 10:58
Show Gist options
  • Save sitano/cbeeb9f990d0b002e0f0 to your computer and use it in GitHub Desktop.
Save sitano/cbeeb9f990d0b002e0f0 to your computer and use it in GitHub Desktop.
Max active spinning ns/op in go runtime 1.6
// 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