mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
added benchmark for assembly vs native popcount
This commit is contained in:
parent
c62cda7d17
commit
8cbf77a11d
6 changed files with 102 additions and 7 deletions
|
|
@ -93,6 +93,7 @@ func (m *Main) Run(args ...string) error {
|
|||
return err
|
||||
} else if addr == "" {
|
||||
return errors.New("port must be specified in config host")
|
||||
|
||||
}
|
||||
|
||||
// Set up profiling.
|
||||
|
|
@ -110,7 +111,7 @@ func (m *Main) Run(args ...string) error {
|
|||
cluster := m.Config.PilosaCluster()
|
||||
|
||||
// Create index to store fragments.
|
||||
index := pilosa.NewIndex()
|
||||
index := pilosa.NewIndex("/tmp/")
|
||||
|
||||
// Create executor for executing queries.
|
||||
e := pilosa.NewExecutor(index)
|
||||
|
|
|
|||
12
popcnt.go
12
popcnt.go
|
|
@ -3,7 +3,7 @@ package pilosa
|
|||
// bit population count, take from
|
||||
// https://code.google.com/p/go/issues/detail?id=4988#c11
|
||||
// credit: https://code.google.com/u/arnehormann/
|
||||
func popcount(x uint64) (n uint64) {
|
||||
func popcntGo(x uint64) (n uint64) {
|
||||
x -= (x >> 1) & 0x5555555555555555
|
||||
x = (x>>2)&0x3333333333333333 + x&0x3333333333333333
|
||||
x += x >> 4
|
||||
|
|
@ -15,7 +15,7 @@ func popcount(x uint64) (n uint64) {
|
|||
func popcntSliceGo(s []uint64) uint64 {
|
||||
cnt := uint64(0)
|
||||
for _, x := range s {
|
||||
cnt += popcount(x)
|
||||
cnt += popcntGo(x)
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ func popcntSliceGo(s []uint64) uint64 {
|
|||
func popcntMaskSliceGo(s, m []uint64) uint64 {
|
||||
cnt := uint64(0)
|
||||
for i := range s {
|
||||
cnt += popcount(s[i] &^ m[i])
|
||||
cnt += popcntGo(s[i] &^ m[i])
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ func popcntMaskSliceGo(s, m []uint64) uint64 {
|
|||
func popcntAndSliceGo(s, m []uint64) uint64 {
|
||||
cnt := uint64(0)
|
||||
for i := range s {
|
||||
cnt += popcount(s[i] & m[i])
|
||||
cnt += popcntGo(s[i] & m[i])
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ func popcntAndSliceGo(s, m []uint64) uint64 {
|
|||
func popcntOrSliceGo(s, m []uint64) uint64 {
|
||||
cnt := uint64(0)
|
||||
for i := range s {
|
||||
cnt += popcount(s[i] | m[i])
|
||||
cnt += popcntGo(s[i] | m[i])
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ func popcntOrSliceGo(s, m []uint64) uint64 {
|
|||
func popcntXorSliceGo(s, m []uint64) uint64 {
|
||||
cnt := uint64(0)
|
||||
for i := range s {
|
||||
cnt += popcount(s[i] ^ m[i])
|
||||
cnt += popcntGo(s[i] ^ m[i])
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,3 +100,10 @@ LOOP popcntXorSliceLoop
|
|||
popcntXorSliceEnd:
|
||||
MOVQ AX, ret+48(FP)
|
||||
RET
|
||||
|
||||
|
||||
TEXT ·popcntAsm(SB),4,$0-16
|
||||
MOVQ x+0(FP), DX
|
||||
POPCNTQ_DX_DX
|
||||
MOVQ DX, ret+8(FP)
|
||||
RET
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ func popcntOrSliceAsm(s, m []uint64) uint64
|
|||
|
||||
func popcntXorSliceAsm(s, m []uint64) uint64
|
||||
|
||||
//go:noescape
|
||||
func popcntAsm(x uint64)uint64
|
||||
|
||||
func popcntSlice(s []uint64) uint64 {
|
||||
if useAsm {
|
||||
return popcntSliceAsm(s)
|
||||
|
|
@ -62,3 +65,11 @@ func popcntXorSlice(s, m []uint64) uint64 {
|
|||
}
|
||||
return popcntXorSliceGo(s, m)
|
||||
}
|
||||
|
||||
func popcnt(x uint64) uint64{
|
||||
if useAsm {
|
||||
return popcntAsm(x)
|
||||
}
|
||||
return popcntGo(x)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,3 +7,4 @@ func popcntMaskSlice(s, m []uint64) uint64 { return popcntMaskSliceGo(s, m) }
|
|||
func popcntAndSlice(s, m []uint64) uint64 { return popcntAndSliceGo(s, m) }
|
||||
func popcntOrSlice(s, m []uint64) uint64 { return popcntOrSliceGo(s, m) }
|
||||
func popcntXorSlice(s, m []uint64) uint64 { return popcntXorSliceGo(s, m) }
|
||||
func popcnt(s uint64) uint64 { return popcntGo(s)}
|
||||
|
|
|
|||
75
popcnt_test.go
Normal file
75
popcnt_test.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package pilosa
|
||||
|
||||
import "testing"
|
||||
|
||||
func BenchmarkPopcntAsm(b *testing.B) {
|
||||
// run the Fib function b.N times
|
||||
for n := 0; n < b.N; n++ {
|
||||
popcntAsm(0xdeadbeef)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPopcntGo(b *testing.B) {
|
||||
// run the Fib function b.N times
|
||||
for n := 0; n < b.N; n++ {
|
||||
popcntGo(0xdeadbeef)
|
||||
}
|
||||
}
|
||||
|
||||
func getData() []uint64 {
|
||||
return []uint64{
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
0xdeadbeef,
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPopcntSliceGo(b *testing.B) {
|
||||
d := getData()
|
||||
for n := 0; n < b.N; n++ {
|
||||
popcntSliceGo(d)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPopcntSliceAsm(b *testing.B) {
|
||||
d := getData()
|
||||
for n := 0; n < b.N; n++ {
|
||||
popcntSliceAsm(d)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPopcntSlice(b *testing.B) {
|
||||
d := getData()
|
||||
for n := 0; n < b.N; n++ {
|
||||
popcntSlice(d)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue