@@ -729,10 +729,12 @@ func TestBaseDeltaPostings(t *testing.T) {
729729 ls [i ] = ls [i - 1 ] + uint32 (rand .Int31n (25 )) + 2
730730 }
731731
732- width := bits .Len32 (ls [len (ls )- 1 ] - ls [0 ])
732+ width := ( bits .Len32 (ls [len (ls )- 1 ] - ls [0 ]) + 7 ) >> 3
733733 buf := encoding.Encbuf {}
734734 for i := 0 ; i < num ; i ++ {
735- buf .PutBits (uint64 (ls [i ]- ls [0 ]), width )
735+ for j := width - 1 ; j >= 0 ; j -- {
736+ buf .B = append (buf .B , byte (((ls [i ]- ls [0 ])>> (8 * uint (j ))& 0xff )))
737+ }
736738 }
737739 // t.Log("(baseDeltaPostings) len of 1000 number = ", len(buf.Get()))
738740
@@ -1100,7 +1102,8 @@ func BenchmarkPostings(b *testing.B) {
11001102 ls := make ([]uint32 , num )
11011103 ls [0 ] = 2
11021104 for i := 1 ; i < num ; i ++ {
1103- ls [i ] = ls [i - 1 ] + uint32 (rand .Int31n (15 )) + 2
1105+ ls [i ] = ls [i - 1 ] + uint32 (rand .Int31n (25 )) + 2
1106+ // ls[i] = ls[i-1] + 2
11041107 }
11051108
11061109 // bigEndianPostings.
@@ -1112,10 +1115,13 @@ func BenchmarkPostings(b *testing.B) {
11121115 b .Log ("bigEndianPostings size =" , len (bufBE ))
11131116
11141117 // baseDeltaPostings.
1115- width := bits .Len32 (ls [len (ls )- 1 ] - ls [0 ])
1118+ width := ( bits .Len32 (ls [len (ls )- 1 ] - ls [0 ]) + 7 ) >> 3
11161119 bufBD := encoding.Encbuf {}
11171120 for i := 0 ; i < num ; i ++ {
1118- bufBD .PutBits (uint64 (ls [i ]- ls [0 ]), width )
1121+ for j := width - 1 ; j >= 0 ; j -- {
1122+ bufBD .B = append (bufBD .B , byte (((ls [i ]- ls [0 ])>> (8 * uint (j ))& 0xff )))
1123+ }
1124+ // bufBD.PutBits(uint64(ls[i]-ls[0]), width)
11191125 }
11201126 b .Log ("baseDeltaPostings size =" , len (bufBD .Get ()))
11211127
@@ -1232,20 +1238,20 @@ func BenchmarkPostings(b *testing.B) {
12321238 testutil .Assert (bench , bep .Err () == nil , "" )
12331239 }
12341240 })
1235- // b.Run("baseDeltaIteration", func(bench *testing.B) {
1236- // bench.ResetTimer()
1237- // bench.ReportAllocs()
1238- // for j := 0; j < bench.N; j++ {
1239- // bdp := newBaseDeltaPostings(bufBD.Get(), ls[0], width, len(ls))
1241+ b .Run ("baseDeltaIteration" , func (bench * testing.B ) {
1242+ bench .ResetTimer ()
1243+ bench .ReportAllocs ()
1244+ for j := 0 ; j < bench .N ; j ++ {
1245+ bdp := newBaseDeltaPostings (bufBD .Get (), ls [0 ], width , len (ls ))
12401246
1241- // for i := 0; i < num; i++ {
1242- // testutil.Assert(bench, bdp.Next() == true, "")
1243- // testutil.Equals(bench, uint64(ls[i]), bdp.At())
1244- // }
1245- // testutil.Assert(bench, bdp.Next() == false, "")
1246- // testutil.Assert(bench, bdp.Err() == nil, "")
1247- // }
1248- // })
1247+ for i := 0 ; i < num ; i ++ {
1248+ testutil .Assert (bench , bdp .Next () == true , "" )
1249+ testutil .Equals (bench , uint64 (ls [i ]), bdp .At ())
1250+ }
1251+ testutil .Assert (bench , bdp .Next () == false , "" )
1252+ testutil .Assert (bench , bdp .Err () == nil , "" )
1253+ }
1254+ })
12491255 // b.Run("deltaBlockIteration", func(bench *testing.B) {
12501256 // bench.ResetTimer()
12511257 // bench.ReportAllocs()
@@ -1316,19 +1322,19 @@ func BenchmarkPostings(b *testing.B) {
13161322 }
13171323 }
13181324 })
1319- // b.Run("baseDeltaSeek", func(bench *testing.B) {
1320- // bench.ResetTimer()
1321- // bench.ReportAllocs()
1322- // for j := 0; j < bench.N; j++ {
1323- // bdp := newBaseDeltaPostings(bufBD.Get(), ls[0], width, len(ls))
1325+ b .Run ("baseDeltaSeek" , func (bench * testing.B ) {
1326+ bench .ResetTimer ()
1327+ bench .ReportAllocs ()
1328+ for j := 0 ; j < bench .N ; j ++ {
1329+ bdp := newBaseDeltaPostings (bufBD .Get (), ls [0 ], width , len (ls ))
13241330
1325- // for _, v := range table {
1326- // testutil.Equals(bench, v.found, bdp.Seek(uint64(v.seek)))
1327- // testutil.Equals(bench, uint64(v.val), bdp.At())
1328- // testutil.Assert(bench, bdp.Err() == nil, "")
1329- // }
1330- // }
1331- // })
1331+ for _ , v := range table {
1332+ testutil .Equals (bench , v .found , bdp .Seek (uint64 (v .seek )))
1333+ testutil .Equals (bench , uint64 (v .val ), bdp .At ())
1334+ testutil .Assert (bench , bdp .Err () == nil , "" )
1335+ }
1336+ }
1337+ })
13321338 // b.Run("deltaBlockSeek", func(bench *testing.B) {
13331339 // bench.ResetTimer()
13341340 // bench.ReportAllocs()
0 commit comments