diff options
author | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:06:33 -0400 |
---|---|---|
committer | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:06:33 -0400 |
commit | c6bd9c80ef5038cca580191148d9b88ab505bcf6 (patch) | |
tree | 596ab05ee81a5d5ad5c351fdef5e78eb50efe708 /src/main.cpp | |
download | sqlite-kv-bench-c6bd9c80ef5038cca580191148d9b88ab505bcf6.tar.gz |
init
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b75640d --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,46 @@ +#include <chrono> +#include <iostream> +#include <print> +#include <string> +#include <vector> + +#include <boost/sqlite.hpp> + +int main(int argc, char **argv) { + if (argc < 2) { + std::println(stderr, "usage: bench <database>"); + return 1; + } + + std::println(stderr, "starting benchmark"); + + boost::sqlite::connection connection{argv[1]}; + + std::vector<std::string> keys; + + std::string line; + while (std::getline(std::cin, line)) { + keys.push_back(line); + } + + std::println(stderr, "slurped {} keys into memory", keys.size()); + + auto start = std::chrono::system_clock::now(); + + auto st = connection.prepare("select kv.value from kv where kv.key=?"); + + for (const auto &key : keys) { + auto row = st.execute({key}); + + auto value = row.current().at(0).get_text(); + } + + auto end = std::chrono::system_clock::now(); + + std::chrono::duration<double> d = end - start; + + std::println(stderr, "selected {} keys in {} ({})", keys.size(), d, + keys.size() / d.count()); + + return 0; +} |