/
smychkov
/
SStorage
Обзор
Документация
Войти
/
smychkov
/
SStorage
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
bench/bench_recovery.cpp
54 строки
2 KB
Андрей Смычков
chore: benchmarks + docs update + remove CMakeLists.txt + legacy data
25 апр 2026, 09:25
25 апр 2026, 09:25
66c16af
Код
Авторство
О чём код?
//============================================================================ // Бенчмарк: время recovery после "крэша" (close + open) //============================================================================ #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; std::string dir = "/tmp/sstorage_bench_recovery_" + std::to_string(::getpid()); ::mkdir(dir.c_str(), 0755); // Фаза 1: записываем данные { 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, "value_payload_for_bench"); } db.flush(); db.close(); } // Фаза 2: замеряем time to open auto start = std::chrono::steady_clock::now(); { Config cfg; cfg.setDataDirectory(dir); Database db(cfg); db.open(); db.close(); } auto end = std::chrono::steady_clock::now(); double sec = std::chrono::duration<double>(end - start).count(); std::cout << "bench_recovery: open() of " << kRecords << " records in " << sec << "s\n"; std::error_code ec; std::filesystem::remove_all(dir, ec); return 0; }