@@ -29,32 +29,30 @@ static void SetupBenchTable(HeapTable& table, int num_rows) {
2929
3030static void BM_ExecutionSeqScan (benchmark::State& state) {
3131 std::string test_dir = " ./bench_exec_scan_" + std::to_string (state.range (0 ));
32+ std::filesystem::remove_all (test_dir);
3233 std::filesystem::create_directories (test_dir);
33- StorageManager disk_manager (test_dir);
34- BufferPoolManager bpm (2000 , disk_manager);
35-
36- Schema schema;
37- schema.add_column (" id" , common::ValueType::TYPE_INT64);
38- schema.add_column (" data" , common::ValueType::TYPE_TEXT);
3934
40- for (auto _ : state) {
41- state.PauseTiming ();
42- auto table = std::make_unique<HeapTable>(" scan_table" , bpm, schema);
35+ {
36+ StorageManager disk_manager (test_dir);
37+ BufferPoolManager bpm (2000 , disk_manager);
38+
39+ Schema schema;
40+ schema.add_column (" id" , common::ValueType::TYPE_INT64);
41+ schema.add_column (" data" , common::ValueType::TYPE_TEXT);
42+
43+ auto table = std::make_shared<HeapTable>(" scan_table" , bpm, schema);
4344 table->create ();
4445 SetupBenchTable (*table, state.range (0 ));
45- state.ResumeTiming ();
4646
47- auto scan_op = std::make_unique<SeqScanOperator>(std::move (table));
48- scan_op->init ();
49- Tuple tuple;
50- while (scan_op->next (tuple)) {
51- benchmark::DoNotOptimize (tuple);
47+ for (auto _ : state) {
48+ auto scan_op = std::make_unique<SeqScanOperator>(table);
49+ scan_op->init ();
50+ scan_op->open ();
51+ Tuple tuple;
52+ while (scan_op->next (tuple)) {
53+ benchmark::DoNotOptimize (tuple);
54+ }
5255 }
53-
54- state.PauseTiming ();
55- std::filesystem::remove_all (test_dir);
56- std::filesystem::create_directories (test_dir);
57- state.ResumeTiming ();
5856 }
5957
6058 state.SetItemsProcessed (state.iterations () * state.range (0 ));
@@ -64,45 +62,43 @@ BENCHMARK(BM_ExecutionSeqScan)->Arg(1000)->Arg(10000);
6462
6563static void BM_ExecutionHashJoin (benchmark::State& state) {
6664 std::string test_dir = " ./bench_exec_join_" + std::to_string (state.range (0 ));
65+ std::filesystem::remove_all (test_dir);
6766 std::filesystem::create_directories (test_dir);
68- StorageManager disk_manager (test_dir);
69- BufferPoolManager bpm (4000 , disk_manager);
70-
71- Schema schema;
72- schema.add_column (" id" , common::ValueType::TYPE_INT64);
73- schema.add_column (" data" , common::ValueType::TYPE_TEXT);
7467
75- for (auto _ : state) {
76- state.PauseTiming ();
77- auto left_table = std::make_unique<HeapTable>(" left_table" , bpm, schema);
68+ {
69+ StorageManager disk_manager (test_dir);
70+ BufferPoolManager bpm (4000 , disk_manager);
71+
72+ Schema schema;
73+ schema.add_column (" id" , common::ValueType::TYPE_INT64);
74+ schema.add_column (" data" , common::ValueType::TYPE_TEXT);
75+
76+ auto left_table = std::make_shared<HeapTable>(" left_table" , bpm, schema);
7877 left_table->create ();
7978 SetupBenchTable (*left_table, state.range (0 ));
8079
81- auto right_table = std::make_unique <HeapTable>(" right_table" , bpm, schema);
80+ auto right_table = std::make_shared <HeapTable>(" right_table" , bpm, schema);
8281 right_table->create ();
8382 SetupBenchTable (*right_table, state.range (0 ));
84- state.ResumeTiming ();
8583
86- auto left_scan = std::make_unique<SeqScanOperator>(std::move (left_table));
87- auto right_scan = std::make_unique<SeqScanOperator>(std::move (right_table));
88-
89- // Join on "id"
90- auto left_key = std::make_unique<ColumnExpr>(" id" );
91- auto right_key = std::make_unique<ColumnExpr>(" id" );
92-
93- auto join_op = std::make_unique<HashJoinOperator>(
94- std::move (left_scan), std::move (right_scan), std::move (left_key), std::move (right_key));
95-
96- join_op->init ();
97- Tuple tuple;
98- while (join_op->next (tuple)) {
99- benchmark::DoNotOptimize (tuple);
84+ for (auto _ : state) {
85+ auto left_scan = std::make_unique<SeqScanOperator>(left_table);
86+ auto right_scan = std::make_unique<SeqScanOperator>(right_table);
87+
88+ // Join on "id"
89+ auto left_key = std::make_unique<ColumnExpr>(" id" );
90+ auto right_key = std::make_unique<ColumnExpr>(" id" );
91+
92+ auto join_op = std::make_unique<HashJoinOperator>(
93+ std::move (left_scan), std::move (right_scan), std::move (left_key), std::move (right_key));
94+
95+ join_op->init ();
96+ join_op->open ();
97+ Tuple tuple;
98+ while (join_op->next (tuple)) {
99+ benchmark::DoNotOptimize (tuple);
100+ }
100101 }
101-
102- state.PauseTiming ();
103- std::filesystem::remove_all (test_dir);
104- std::filesystem::create_directories (test_dir);
105- state.ResumeTiming ();
106102 }
107103
108104 state.SetItemsProcessed (state.iterations () * state.range (0 ));
0 commit comments