scan.cpp 3.83 KB
Newer Older
Philipp Götze's avatar
Philipp Götze committed
1
/*
2
 * Copyright (C) 2017-2019 DBIS Group - TU Ilmenau, All Rights Reserved.
Philipp Götze's avatar
Philipp Götze committed
3
 *
4
 * This file is part of our NVM-based Data Structures repository.
Philipp Götze's avatar
Philipp Götze committed
5
 *
6
7
8
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
Philipp Götze's avatar
Philipp Götze committed
9
 *
10
11
12
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
Philipp Götze's avatar
Philipp Götze committed
13
 *
14
15
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
Philipp Götze's avatar
Philipp Götze committed
16
17
18
19
 */

#include <unistd.h>
#include "benchmark/benchmark.h"
20
#include "common.hpp"
Philipp Götze's avatar
Philipp Götze committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

using namespace dbis::ptable;

static void BM_RangeScan(benchmark::State &state) {
  pool<root> pop;

  if (access(path.c_str(), F_OK) != 0) {
    insert(pop, path, NUM_TUPLES);
  } else {
    LOG("Warning: " << path << " already exists");
    pop = pool<root>::open(path, LAYOUT);
  }

  auto pTable = pop.root()->pTable;

  /* RangeScan using Block iterator */
  for (auto _ : state) {
38
39
40
    auto iter =
        pTable->rangeScan(ColumnRangeMap({{0, {(int)state.range(0), (int)state.range(1)}}}));
    for (const auto &tp : iter) {
Philipp Götze's avatar
Philipp Götze committed
41
42
43
44
45
      tp;
    }
  }
  pop.close();
}
46
static void KeyRangeArguments(benchmark::internal::Benchmark *b) {
Philipp Götze's avatar
Philipp Götze committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  for (const auto &arg : KEY_RANGES) b->Args(arg);
}
BENCHMARK(BM_RangeScan)->Apply(KeyRangeArguments);

static void BM_NonKeyRangeScan(benchmark::State &state) {
  pool<root> pop;

  if (access(path.c_str(), F_OK) != 0) {
    insert(pop, path, NUM_TUPLES);
  } else {
    LOG("Warning: " << path << " already exists");
    pop = pool<root>::open(path, LAYOUT);
  }

  auto pTable = pop.root()->pTable;

  /* RangeScan using Block iterator */
  for (auto _ : state) {
65
66
67
68
    auto iter =
        pTable->rangeScan(ColumnRangeMap({{0, {(int)state.range(0), (int)state.range(1)}},
                                          {3, {(double)state.range(2), (double)state.range(3)}}}));
    for (const auto &tp : iter) {
Philipp Götze's avatar
Philipp Götze committed
69
70
71
72
73
      tp;
    }
  }
  pop.close();
}
74
static void NonKeyRangeArguments(benchmark::internal::Benchmark *b) {
Philipp Götze's avatar
Philipp Götze committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  for (const auto &arg : NON_KEY_RANGES) b->Args(arg);
}
BENCHMARK(BM_NonKeyRangeScan)->Apply(NonKeyRangeArguments);

static void BM_PBPTreeKeyScan(benchmark::State &state) {
  pool<root> pop;

  if (access(path.c_str(), F_OK) != 0) {
    insert(pop, path, NUM_TUPLES);
  } else {
    LOG("Warning: " << path << " already exists");
    pop = pool<root>::open(path, LAYOUT);
  }

  auto pTable = pop.root()->pTable;

  for (auto _ : state) {
    /* Scan via Index scan */
93
94
    pTable->rangeScan2(state.range(0), state.range(1),
                       [](int k, const PTuple<int, MyTuple> tp) { tp; });
Philipp Götze's avatar
Philipp Götze committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  }

  pop.close();
}
BENCHMARK(BM_PBPTreeKeyScan)->Apply(KeyRangeArguments);

static void BM_PBPTreeScan(benchmark::State &state) {
  pool<root> pop;

  if (access(path.c_str(), F_OK) != 0) {
    insert(pop, path, NUM_TUPLES);
  } else {
    LOG("Warning: " << path << " already exists");
    pop = pool<root>::open(path, LAYOUT);
  }

111
  auto &pTable = *pop.root()->pTable;
Philipp Götze's avatar
Philipp Götze committed
112
113
114

  for (auto _ : state) {
    /* Scan via PTuple iterator */
115
    auto eIter = pTable.end();
116
117
118
119
    auto iter = pTable.select([&](const PTuple<int, MyTuple> &tp) {
      return (tp.get<0>() >= state.range(0)) && (tp.get<0>() <= state.range(1)) &&
             (tp.get<3>() >= state.range(2)) && (tp.get<3>() <= state.range(3));
    });
Philipp Götze's avatar
Philipp Götze committed
120
121
122
123
124
125
    for (; iter != eIter; iter++) {
      iter;
      //(*iter).get<0>();
    }
  }

126
  transaction::run(pop, [&] { delete_persistent<PTableType>(pop.root()->pTable); });
Philipp Götze's avatar
Philipp Götze committed
127
  pop.close();
128
  pmempool_rm(path.c_str(), 0);
Philipp Götze's avatar
Philipp Götze committed
129
130
131
132
}
BENCHMARK(BM_PBPTreeScan)->Apply(NonKeyRangeArguments);

BENCHMARK_MAIN();