diff options
| author | Douglas Rumbaugh <dbr4@psu.edu> | 2023-06-13 14:48:03 -0400 |
|---|---|---|
| committer | Douglas Rumbaugh <dbr4@psu.edu> | 2023-06-13 14:48:03 -0400 |
| commit | 0e8d1ef77ad8db2b2491ae92874eb21b7986d59b (patch) | |
| tree | de9d2edf558b68b09506b0d75a1ac7aa31adb8c4 /benchmarks/include | |
| parent | 7559704587aa2c77ad4193bd54ec41412a14bb4b (diff) | |
| download | dynamic-extension-0e8d1ef77ad8db2b2491ae92874eb21b7986d59b.tar.gz | |
Benchmark refactoring/cleanup
Diffstat (limited to 'benchmarks/include')
| -rw-r--r-- | benchmarks/include/bench.h | 43 | ||||
| -rw-r--r-- | benchmarks/include/bench_utility.h | 47 |
2 files changed, 79 insertions, 11 deletions
diff --git a/benchmarks/include/bench.h b/benchmarks/include/bench.h index d82da48..6a9c263 100644 --- a/benchmarks/include/bench.h +++ b/benchmarks/include/bench.h @@ -1,3 +1,13 @@ +/* + * benchmarks/include/bench.h + * + * Copyright (C) 2023 Douglas Rumbaugh <drumbaugh@psu.edu> + * + * All rights reserved. Published under the Modified BSD License. + * + */ +#pragma once + #include "bench_utility.h" template <typename DE, de::RecordInterface R, bool PROGRESS=true, size_t BATCH=1000> @@ -64,4 +74,37 @@ static bool insert_tput_bench(DE &de_index, std::fstream &file, size_t insert_cn return continue_benchmark; } +template <typename DE, de::RecordInterface R, typename QP, bool PROGRESS=true> +static bool query_latency_bench(DE &de_index, std::vector<QP> queries, size_t trial_cnt=100) { + char progbuf[25]; + if constexpr (PROGRESS) { + sprintf(progbuf, "querying:"); + } + + size_t total_time = 0; + size_t total_results = 0; + + for (size_t i=0; i<trial_cnt; i++) { + if constexpr (PROGRESS) { + progress_update((double) (i) / (double) trial_cnt, progbuf); + } + + auto start = std::chrono::high_resolution_clock::now(); + for (size_t j=0; j<queries.size(); j++) { + auto res = de_index.query(&queries[j]); + total_results += res.size(); + } + auto stop = std::chrono::high_resolution_clock::now(); + + total_time += std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start).count(); + } + + progress_update(1.0, progbuf); + + size_t query_latency = total_time / (trial_cnt * queries.size()); + fprintf(stdout, "%ld\t", query_latency); + fflush(stdout); + + return true; +} diff --git a/benchmarks/include/bench_utility.h b/benchmarks/include/bench_utility.h index 78d6415..f208487 100644 --- a/benchmarks/include/bench_utility.h +++ b/benchmarks/include/bench_utility.h @@ -1,5 +1,13 @@ -#ifndef H_BENCH -#define H_BENCH +/* + * benchmarks/include/bench_utility.h + * + * Copyright (C) 2023 Douglas Rumbaugh <drumbaugh@psu.edu> + * + * All rights reserved. Published under the Modified BSD License. + * + */ +#pragma once + #include "framework/DynamicExtension.h" #include "shard/WSS.h" #include "shard/MemISAM.h" @@ -29,7 +37,7 @@ typedef de::WeightedRecord<key_type, value_type, weight_type> WRec; typedef de::Record<key_type, value_type> Rec; typedef de::DynamicExtension<WRec, de::WSS<WRec>, de::WSSQuery<WRec>> ExtendedWSS; -typedef de::DynamicExtension<Rec, de::TrieSpline<Rec>, de::TrieSplineRangeQuery<Rec>> ExtendedTS; +typedef de::DynamicExtension<Rec, de::TrieSpline<Rec>, de::TrieSplineRangeQuery<Rec>> ExtendedTSRQ; typedef de::DynamicExtension<Rec, de::PGM<Rec>, de::PGMRangeQuery<Rec>> ExtendedPGM; static gsl_rng *g_rng; @@ -82,6 +90,31 @@ static void delete_bench_env() delete g_to_delete; } +/* + * NOTE: The QP type must have lower_bound and upper_bound attributes, which + * this function will initialize. Any other query parameter attributes must + * be manually initialized after the call. + */ +template <typename QP> +static std::vector<QP> read_range_queries(std::string fname, double selectivity) { + std::vector<QP> queries; + + FILE *qf = fopen(fname.c_str(), "r"); + size_t start, stop; + double sel; + while (fscanf(qf, "%zu%zu%lf\n", &start, &stop, &sel) != EOF) { + if (start < stop && std::abs(sel - selectivity) < 0.1) { + QP q; + q.lower_bound = start; + q.upper_bound = stop; + queries.push_back(q); + } + } + fclose(qf); + + return queries; +} + template <de::RecordInterface R> static bool next_record(std::fstream &file, R &record) { @@ -213,12 +246,6 @@ static bool warmup(std::fstream &file, DE &extended_index, size_t count, } } - /* - if (progress) { - progress_update(1, "warming up:"); - } - */ - return true; } @@ -232,5 +259,3 @@ static void reset_de_perf_metrics() { RESET_IO_CNT(); } - -#endif // H_BENCH |