From ef3b24358e508c5220d8b2548ec7207936794c66 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 4 Dec 2014 15:49:02 +0100 Subject: hide the implementation detail of which key/value store we use also makes transactions "implicit" where necessary. this will make trying out other k/v stores a bit easier now as well. --- store/test/storagebenchmark.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'store/test/storagebenchmark.cpp') diff --git a/store/test/storagebenchmark.cpp b/store/test/storagebenchmark.cpp index 6fc50f6..6f9f18b 100644 --- a/store/test/storagebenchmark.cpp +++ b/store/test/storagebenchmark.cpp @@ -1,12 +1,14 @@ #include #include "calendar_generated.h" + #include #include + +#include #include #include #include -#include #include "store/database.h" @@ -75,7 +77,10 @@ private Q_SLOTS: QFETCH(bool, useDb); QFETCH(int, count); - Database db(dbPath); + Database *db = 0; + if (useDb) { + db = new Database(dbPath); + } std::ofstream myfile; myfile.open(filePath.toStdString()); @@ -85,21 +90,22 @@ private Q_SLOTS: time.start(); { - auto transaction = db.startTransaction(); auto event = createEvent(); for (int i = 0; i < count; i++) { - if (useDb && i > 0 && (i % 10000 == 0)) { - db.endTransaction(transaction); - transaction = db.startTransaction(); - } - if (useDb) { - db.write(keyPrefix + std::to_string(i), event, transaction); + if (db) { + if (i % 10000 == 0) { + db->commitTransaction(); + db->startTransaction(); + } + + db->write(keyPrefix + std::to_string(i), event); } else { myfile << event; } } - if (useDb) { - db.endTransaction(transaction); + + if (db) { + db->commitTransaction(); } else { myfile.close(); } @@ -110,8 +116,8 @@ private Q_SLOTS: time.start(); { for (int i = 0; i < count; i++) { - if (useDb) { - db.read(keyPrefix + std::to_string(i)); + if (db) { + db->read(keyPrefix + std::to_string(i), [](void *ptr, int size){}); } } } -- cgit v1.2.3