-
Notifications
You must be signed in to change notification settings - Fork 0
/
popcnt_test.go
38 lines (32 loc) · 996 Bytes
/
popcnt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package popcnt
import (
"math/bits"
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSimdPopcntQuad(t *testing.T) {
rand.Seed(time.Now().UnixNano())
for i := 0; i < 1; i++ {
nums := [4]uint64{rand.Uint64(), rand.Uint64(), rand.Uint64(), rand.Uint64()}
assert.Equal(t, SimdPopcntQuad(nums), serialPopcntQuad(nums))
}
}
func BenchmarkSimdPopcntQuad(b *testing.B) {
rand.Seed(time.Now().UnixNano())
nums := [4]uint64{rand.Uint64(), rand.Uint64(), rand.Uint64(), rand.Uint64()}
for i := 0; i < b.N; i++ {
SimdPopcntQuad(nums)
}
}
func BenchmarkSerial(b *testing.B) {
rand.Seed(time.Now().UnixNano())
nums := [4]uint64{rand.Uint64(), rand.Uint64(), rand.Uint64(), rand.Uint64()}
for i := 0; i < b.N; i++ {
serialPopcntQuad(nums)
}
}
func serialPopcntQuad(nums [4]uint64) [4]uint64 {
return [4]uint64{uint64(bits.OnesCount64(nums[0])), uint64(bits.OnesCount64(nums[1])), uint64(bits.OnesCount64(nums[2])), uint64(bits.OnesCount64(nums[3]))}
}