/
smychkov
/
SStorage
Обзор
Документация
Войти
/
smychkov
/
SStorage
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
bench/bench_scan.cpp
56 строк
2 KB
Андрей Смычков
chore: benchmarks + docs update + remove CMakeLists.txt + legacy data
25 апр 2026, 09:25
25 апр 2026, 09:25
66c16af
Код
Авторство
О чём код?
//============================================================================ // Бенчмарк: throughput scan-операций //============================================================================ #include "../src/core/database.hpp" #include <chrono> #include <cstdio> #include <cstdlib> #include <filesystem> #include <iostream> #include <string> #include <sys/stat.h> #include <unistd.h> using namespace sstorage; int main(int argc, char** argv) { const int kRecords = argc > 1 ? std::atoi(argv[1]) : 100000; const int kScans = argc > 2 ? std::atoi(argv[2]) : 1000; const size_t kPerScan = 100; std::string dir = "/tmp/sstorage_bench_scan_" + std::to_string(::getpid()); ::mkdir(dir.c_str(), 0755); Config cfg; cfg.setDataDirectory(dir); Database db(cfg); db.open(); for (int i = 0; i < kRecords; ++i) { char k[32]; std::snprintf(k, sizeof(k), "key_%08d", i); db.put(k, "some_value"); } db.flush(); auto start = std::chrono::steady_clock::now(); size_t totalRows = 0; for (int i = 0; i < kScans; ++i) { int base = rand() % (kRecords - static_cast<int>(kPerScan)); char from[32], to[32]; std::snprintf(from, sizeof(from), "key_%08d", base); std::snprintf(to, sizeof(to), "key_%08d", base + static_cast<int>(kPerScan) - 1); auto r = db.scan(from, to, kPerScan); totalRows += r.size(); } auto end = std::chrono::steady_clock::now(); double sec = std::chrono::duration<double>(end - start).count(); std::cout << "bench_scan: " << kScans << " scans in " << sec << "s = " << (kScans / sec) << " scans/sec (total_rows=" << totalRows << ")\n"; db.close(); std::error_code ec; std::filesystem::remove_all(dir, ec); return 0; }