Skip to content

Instantly share code, notes, and snippets.

@dspezia
Created July 22, 2020 22:52
Show Gist options
  • Save dspezia/6c6e68d7b0b940b9bc314761a7da245f to your computer and use it in GitHub Desktop.
Save dspezia/6c6e68d7b0b940b9bc314761a7da245f to your computer and use it in GitHub Desktop.
Example Go frequency measurement
package main
import "bytes"
import "time"
import "fmt"
func ClusterSlot(key []byte) uint16 {
if start := bytes.IndexByte(key, '{'); start >= 0 {
if end := bytes.IndexByte(key[start+1:], '}'); end > 0 {
key = key[start+1 : start+1+end]
}
}
return 0
}
func didier_freq()
func didier_count( n int ) int {
x := n
for i:=0; i< 1<<32 ; i++ {
x += i
}
return x
}
func main() {
//ClusterSlot(nil)
//_ = didier_count(1000)
Add(1<<34)
t := time.Now()
Add(1<<34)
t2 := time.Now()
dur := t2.Sub(t).Seconds()
fmt.Println(float64(1<<34) / dur / 1.0e9)
}
// +build ignore
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
// . "github.com/mmcloughlin/avo/reg"
)
func main() {
TEXT("Add", NOSPLIT, "func(n int64) int")
x := Load(Param("n"), GP64())
Label("loop")
for i:=0; i<4; i++ {
SUBQ(U8(1),x)
}
JNE(LabelRef("loop"))
Store(x, ReturnIndex(0))
RET()
Generate()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment