12
12
#include " base/gtest.h"
13
13
#include " base/logging.h"
14
14
#include " core/mi_memory_resource.h"
15
+ #include " io/file.h"
16
+ #include " io/line_reader.h"
15
17
16
18
extern " C" {
17
19
#include " redis/listpack.h"
@@ -24,7 +26,7 @@ using namespace std;
24
26
using namespace testing ;
25
27
using absl::StrCat;
26
28
27
- static int _ql_verify_compress (const QList& ql) {
29
+ static int ql_verify_compress (const QList& ql) {
28
30
int errors = 0 ;
29
31
unsigned compress_param = ql.compress_param ();
30
32
if (compress_param > 0 ) {
@@ -115,19 +117,23 @@ static int ql_verify(const QList& ql, uint32_t nc, uint32_t count, uint32_t head
115
117
errors++;
116
118
}
117
119
118
- errors += _ql_verify_compress (ql);
120
+ errors += ql_verify_compress (ql);
119
121
return errors;
120
122
}
121
123
124
+ static void SetupMalloc () {
125
+ // configure redis lib zmalloc which requires mimalloc heap to work.
126
+ auto * tlh = mi_heap_get_backing ();
127
+ init_zmalloc_threadlocal (tlh);
128
+ }
129
+
122
130
class QListTest : public ::testing::Test {
123
131
protected:
124
132
QListTest () : mr_(mi_heap_get_backing()) {
125
133
}
126
134
127
135
static void SetUpTestSuite () {
128
- // configure redis lib zmalloc which requires mimalloc heap to work.
129
- auto * tlh = mi_heap_get_backing ();
130
- init_zmalloc_threadlocal (tlh);
136
+ SetupMalloc ();
131
137
}
132
138
133
139
static void TearDownTestSuite () {
@@ -848,4 +854,53 @@ TEST_P(OptionsTest, IndexFrom500) {
848
854
ASSERT_FALSE (it.Next ());
849
855
}
850
856
857
+ static void BM_QListCompress (benchmark::State& state) {
858
+ SetupMalloc ();
859
+
860
+ string path = base::ProgramRunfile (" testdata/list.txt.zst" );
861
+ io::Result<io::Source*> src = io::OpenUncompressed (path);
862
+ CHECK (src) << src.error ();
863
+ io::LineReader lr (*src, TAKE_OWNERSHIP);
864
+ string_view line;
865
+ vector<string> lines;
866
+ while (lr.Next (&line)) {
867
+ lines.push_back (string (line));
868
+ }
869
+
870
+ while (state.KeepRunning ()) {
871
+ QList ql (-2 , state.range (0 )); // uses differrent compression modes, see below.
872
+ for (const string& l : lines) {
873
+ ql.Push (l, QList::TAIL);
874
+ }
875
+ DVLOG (1 ) << ql.node_count () << " , " << ql.MallocUsed (true );
876
+ }
877
+ }
878
+ BENCHMARK (BM_QListCompress)
879
+ ->Arg(0 ) // no compression
880
+ ->Arg(1 ) // compress all nodes but edges.
881
+ ->Arg(4 ); // compress all nodes but 4 nodes from edges.
882
+
883
+ static void BM_QListUncompress (benchmark::State& state) {
884
+ SetupMalloc ();
885
+
886
+ string path = base::ProgramRunfile (" testdata/list.txt.zst" );
887
+ io::Result<io::Source*> src = io::OpenUncompressed (path);
888
+ CHECK (src) << src.error ();
889
+ io::LineReader lr (*src, TAKE_OWNERSHIP);
890
+ string_view line;
891
+ QList ql (-2 , state.range (0 ));
892
+
893
+ while (lr.Next (&line)) {
894
+ ql.Push (line, QList::TAIL);
895
+ }
896
+
897
+ LOG (INFO) << " MallocUsed " << ql.compress_param () << " : " << ql.MallocUsed (true ) << " , "
898
+ << ql.MallocUsed (false );
899
+
900
+ while (state.KeepRunning ()) {
901
+ ql.Iterate ([](const QList::Entry& e) { return true ; }, 0 , -1 );
902
+ }
903
+ }
904
+ BENCHMARK (BM_QListUncompress)->Arg(0 )->Arg(1 )->Arg(4 );
905
+
851
906
} // namespace dfly
0 commit comments