From fbd35044dc343dbd17d475b860c6019077271efc Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 10 Dec 2014 21:55:32 +0100 Subject: Benchmark scan vs. direct lookup. The scan is always worst-case since it goes through all values. --- tests/storagebenchmark.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index 665008d..bfdd2ce 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp @@ -79,9 +79,9 @@ private Q_SLOTS: QFETCH(bool, useDb); QFETCH(int, count); - Storage *store = 0; + QScopedPointer store; if (useDb) { - store = new Storage(testDataPath, dbName, Storage::ReadWrite); + store.reset(new Storage(testDataPath, dbName, Storage::ReadWrite)); } std::ofstream myfile; @@ -133,8 +133,40 @@ private Q_SLOTS: } else { qDebug() << "File reading is not implemented."; } + } + + void testScan() + { + QScopedPointer store(new Storage(testDataPath, dbName, Storage::ReadOnly)); + + QBENCHMARK { + int hit = 0; + store->scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { + if (std::string(static_cast(keyValue), keySize) == "key10000") { + qDebug() << "hit"; + hit++; + } + return true; + }); + QCOMPARE(hit, 1); + } + } - delete store; + void testKeyLookup() + { + QScopedPointer store(new Storage(testDataPath, dbName, Storage::ReadOnly)); + + QBENCHMARK { + int hit = 0; + store->scan("key40000", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { + if (std::string(static_cast(keyValue), keySize) == "foo") { + qDebug() << "hit"; + } + hit++; + return true; + }); + QCOMPARE(hit, 1); + } } void testBufferCreation() -- cgit v1.2.3