@@ -106,7 +106,7 @@ func TestBatchPerCPUHash(t *testing.T) {
106
106
}
107
107
defer m .Close ()
108
108
109
- possibleCPUs , err := internal . PossibleCPUs ()
109
+ possibleCPUs , err := PossibleCPU ()
110
110
if err != nil {
111
111
t .Fatal (err )
112
112
}
@@ -1982,38 +1982,74 @@ func BenchmarkMarshaling(b *testing.B) {
1982
1982
}
1983
1983
1984
1984
func BenchmarkPerCPUMarshalling (b * testing.B ) {
1985
+ batch := 1024
1985
1986
newMap := func (valueSize uint32 ) * Map {
1986
1987
m , err := NewMap (& MapSpec {
1987
1988
Type : PerCPUHash ,
1988
1989
KeySize : 8 ,
1989
1990
ValueSize : valueSize ,
1990
- MaxEntries : 1 ,
1991
+ MaxEntries : uint32 ( batch ) ,
1991
1992
})
1992
1993
if err != nil {
1993
1994
b .Fatal (err )
1994
1995
}
1995
1996
return m
1996
1997
}
1997
1998
1998
- key := uint64 (1 )
1999
- val := []uint64 {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 }
1999
+ possibleCPUs , err := PossibleCPU ()
2000
+ if err != nil {
2001
+ b .Fatal (err )
2002
+ }
2003
+
2004
+ val := make ([]uint64 , possibleCPUs )
2005
+ for i := range val {
2006
+ val [i ] = uint64 (i + 1 )
2007
+ }
2000
2008
2001
2009
m := newMap (8 )
2002
- if err := m .Put (key , val [0 :]); err != nil {
2003
- b .Fatal (err )
2010
+ for i := 0 ; i < batch ; i ++ {
2011
+ key := uint64 (i + 1 )
2012
+ if err := m .Put (key , val ); err != nil {
2013
+ b .Fatal (err )
2014
+ }
2004
2015
}
2005
2016
b .Cleanup (func () { m .Close () })
2006
2017
2007
- b .Run ("reflection " , func (b * testing.B ) {
2018
+ b .Run ("Lookup " , func (b * testing.B ) {
2008
2019
b .ReportAllocs ()
2009
2020
b .ResetTimer ()
2010
2021
2011
2022
var value []uint64
2012
2023
2013
2024
for i := 0 ; i < b .N ; i ++ {
2014
- err := m .Lookup (unsafe .Pointer (& key ), & value )
2015
- if err != nil {
2016
- b .Fatal ("Can't get key:" , err )
2025
+ for j := 0 ; j < batch ; j ++ {
2026
+ key := uint64 (j + 1 )
2027
+ err := m .Lookup (unsafe .Pointer (& key ), & value )
2028
+ if err != nil {
2029
+ b .Fatal ("Can't get key:" , err )
2030
+ }
2031
+ }
2032
+ }
2033
+ })
2034
+ b .Run ("BatchLookup" , func (b * testing.B ) {
2035
+ b .ReportAllocs ()
2036
+ b .ResetTimer ()
2037
+
2038
+ var (
2039
+ keys = make ([]uint64 , batch )
2040
+ values = make ([]uint64 , batch * possibleCPUs )
2041
+ )
2042
+
2043
+ for i := 0 ; i < b .N ; i ++ {
2044
+ var key uint64
2045
+ count , err := m .BatchLookup (nil , unsafe .Pointer (& key ), keys , values , & BatchOptions {})
2046
+ if count <= 0 {
2047
+ if err != nil {
2048
+ b .Fatal ("Can't get batch:" , err )
2049
+ }
2050
+ }
2051
+ if count != batch {
2052
+ b .Fatalf ("Can't get batch: %d" , count )
2017
2053
}
2018
2054
}
2019
2055
})
0 commit comments