bst_vs_heap_vs_hashmap: configurable seed, make code a bit nicer

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-11-15 00:00:00 +00:00
parent d092ca068d
commit c14d5dfeba
2 changed files with 36 additions and 26 deletions

View File

@@ -11111,8 +11111,12 @@ It has been used to answer:
To benchmark on the host, we do: To benchmark on the host, we do:
.... ....
./build-userland-in-tree --force-rebuild --optimization-level 3 ./userland/cpp/bst_vs_heap_vs_hashmap.cpp ./build-userland-in-tree \
./userland/cpp/bst_vs_heap_vs_hashmap.out 10000000 10000 | tee bst_vs_heap_vs_hashmap.dat --force-rebuild \
--optimization-level 3 \
./userland/cpp/bst_vs_heap_vs_hashmap.cpp \
;
./userland/cpp/bst_vs_heap_vs_hashmap.out 10000000 10000 0 | tee bst_vs_heap_vs_hashmap.dat
gnuplot \ gnuplot \
-e 'input_noext="bst_vs_heap_vs_hashmap"' \ -e 'input_noext="bst_vs_heap_vs_hashmap"' \
-e 'heap_zoom_max=50' \ -e 'heap_zoom_max=50' \
@@ -11139,7 +11143,7 @@ To benchmark on gem5, we first build the benchmark with <<m5ops-instructions>> e
--emulator gem5 \ --emulator gem5 \
--static \ --static \
--userland userland/cpp/bst_vs_heap_vs_hashmap.cpp \ --userland userland/cpp/bst_vs_heap_vs_hashmap.cpp \
--userland-args='100000' \ --userland-args='100000 1 0' \
-- \ -- \
--cpu-type=DerivO3CPU \ --cpu-type=DerivO3CPU \
--caches \ --caches \

View File

@@ -14,11 +14,12 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
typedef uint64_t I; typedef uint64_t I;
std::vector<I> randoms; std::vector<I> randoms;
size_t i, j, n, granule, base; size_t i, n, granule, base;
std::priority_queue<I> heap; std::priority_queue<I> heap;
std::set<I> bst; std::set<I> bst;
std::unordered_set<I> hashmap; std::unordered_set<I> hashmap;
unsigned int seed = std::random_device()(); unsigned int seed;
size_t j = 0;
// CLI arguments. // CLI arguments.
if (argc > 1) { if (argc > 1) {
@@ -26,17 +27,16 @@ int main(int argc, char **argv) {
} else { } else {
n = 10; n = 10;
} }
#ifdef LKMC_M5OPS_ENABLE
// Let's comment useless stuff out to speed up gem5 simulations.
granule = 1;
j = 0;
#else
if (argc > 2) { if (argc > 2) {
granule = std::stoi(argv[2]); granule = std::stoi(argv[2]);
} else { } else {
granule = 1; granule = 1;
} }
#endif if (argc > 3) {
seed = std::stoi(argv[3]);
} else {
seed = std::random_device()();
}
// Action. // Action.
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
@@ -51,42 +51,48 @@ int main(int argc, char **argv) {
base = i * granule; base = i * granule;
// Heap. // Heap.
#ifndef LKMC_M5OPS_ENABLE #ifdef LKMC_M5OPS_ENABLE
LKMC_M5OPS_RESETSTATS;
#else
start = clk::now(); start = clk::now();
for (j = 0; j < granule; ++j) { for (j = 0; j < granule; ++j) {
#endif #endif
LKMC_M5OPS_RESETSTATS; heap.emplace(randoms[base + j]);
heap.emplace(randoms[base + j]); #ifdef LKMC_M5OPS_ENABLE
LKMC_M5OPS_DUMPSTATS; LKMC_M5OPS_DUMPSTATS;
#ifndef LKMC_M5OPS_ENABLE #else
} }
end = clk::now(); end = clk::now();
auto dt_heap = (end - start) / granule; auto dt_heap = (end - start) / granule;
#endif #endif
// BST. // BST.
#ifndef LKMC_M5OPS_ENABLE #ifdef LKMC_M5OPS_ENABLE
LKMC_M5OPS_RESETSTATS;
#else
start = clk::now(); start = clk::now();
for (j = 0; j < granule; ++j) { for (j = 0; j < granule; ++j) {
#endif #endif
LKMC_M5OPS_RESETSTATS; bst.insert(randoms[base + j]);
bst.insert(randoms[base + j]); #ifdef LKMC_M5OPS_ENABLE
LKMC_M5OPS_DUMPSTATS; LKMC_M5OPS_DUMPSTATS;
#ifndef LKMC_M5OPS_ENABLE #else
} }
end = clk::now(); end = clk::now();
auto dt_bst = (end - start) / granule; auto dt_bst = (end - start) / granule;
#endif #endif
// Hashmap. // Hashmap.
#ifndef LKMC_M5OPS_ENABLE #ifdef LKMC_M5OPS_ENABLE
LKMC_M5OPS_RESETSTATS;
#else
start = clk::now(); start = clk::now();
for (j = 0; j < granule; ++j) { for (j = 0; j < granule; ++j) {
#endif #endif
LKMC_M5OPS_RESETSTATS; hashmap.insert(randoms[base + j]);
hashmap.insert(randoms[base + j]); #ifdef LKMC_M5OPS_ENABLE
LKMC_M5OPS_DUMPSTATS; LKMC_M5OPS_DUMPSTATS;
#ifndef LKMC_M5OPS_ENABLE #else
} }
end = clk::now(); end = clk::now();
auto dt_hashmap = (end - start) / granule; auto dt_hashmap = (end - start) / granule;