diff options
Diffstat (limited to 'tests/storagebenchmark.cpp')
-rw-r--r-- | tests/storagebenchmark.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index 8498df9..a1ddcc9 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp | |||
@@ -18,7 +18,7 @@ using namespace flatbuffers; | |||
18 | 18 | ||
19 | static QByteArray createEvent() | 19 | static QByteArray createEvent() |
20 | { | 20 | { |
21 | static const size_t attachmentSize = 1024*2; // 2KB | 21 | static const size_t attachmentSize = 1024 * 2; // 2KB |
22 | static uint8_t rawData[attachmentSize]; | 22 | static uint8_t rawData[attachmentSize]; |
23 | static FlatBufferBuilder fbb; | 23 | static FlatBufferBuilder fbb; |
24 | fbb.Clear(); | 24 | fbb.Clear(); |
@@ -26,13 +26,13 @@ static QByteArray createEvent() | |||
26 | uint8_t *rawDataPtr = Q_NULLPTR; | 26 | uint8_t *rawDataPtr = Q_NULLPTR; |
27 | auto summary = fbb.CreateString("summary"); | 27 | auto summary = fbb.CreateString("summary"); |
28 | auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr); | 28 | auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr); |
29 | //auto data = fbb.CreateVector(rawData, attachmentSize); | 29 | // auto data = fbb.CreateVector(rawData, attachmentSize); |
30 | Calendar::EventBuilder eventBuilder(fbb); | 30 | Calendar::EventBuilder eventBuilder(fbb); |
31 | eventBuilder.add_summary(summary); | 31 | eventBuilder.add_summary(summary); |
32 | eventBuilder.add_attachment(data); | 32 | eventBuilder.add_attachment(data); |
33 | auto eventLocation = eventBuilder.Finish(); | 33 | auto eventLocation = eventBuilder.Finish(); |
34 | Calendar::FinishEventBuffer(fbb, eventLocation); | 34 | Calendar::FinishEventBuffer(fbb, eventLocation); |
35 | memcpy((void*)rawDataPtr, rawData, attachmentSize); | 35 | memcpy((void *)rawDataPtr, rawData, attachmentSize); |
36 | } | 36 | } |
37 | 37 | ||
38 | return QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | 38 | return QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); |
@@ -45,7 +45,7 @@ class StorageBenchmark : public QObject | |||
45 | { | 45 | { |
46 | Q_OBJECT | 46 | Q_OBJECT |
47 | private: | 47 | private: |
48 | //This should point to a directory on disk and not a ramdisk (since we're measuring performance) | 48 | // This should point to a directory on disk and not a ramdisk (since we're measuring performance) |
49 | QString testDataPath; | 49 | QString testDataPath; |
50 | QString dbName; | 50 | QString dbName; |
51 | QString filePath; | 51 | QString filePath; |
@@ -76,7 +76,7 @@ private slots: | |||
76 | 76 | ||
77 | QTime time; | 77 | QTime time; |
78 | time.start(); | 78 | time.start(); |
79 | //Test db write time | 79 | // Test db write time |
80 | { | 80 | { |
81 | auto transaction = store->createTransaction(Sink::Storage::ReadWrite); | 81 | auto transaction = store->createTransaction(Sink::Storage::ReadWrite); |
82 | for (int i = 0; i < count; i++) { | 82 | for (int i = 0; i < count; i++) { |
@@ -91,7 +91,7 @@ private slots: | |||
91 | qreal dbWriteDuration = time.restart(); | 91 | qreal dbWriteDuration = time.restart(); |
92 | qreal dbWriteOpsPerMs = count / dbWriteDuration; | 92 | qreal dbWriteOpsPerMs = count / dbWriteDuration; |
93 | 93 | ||
94 | //Test file write time | 94 | // Test file write time |
95 | { | 95 | { |
96 | std::ofstream myfile; | 96 | std::ofstream myfile; |
97 | myfile.open(filePath.toStdString()); | 97 | myfile.open(filePath.toStdString()); |
@@ -103,7 +103,7 @@ private slots: | |||
103 | qreal fileWriteDuration = time.restart(); | 103 | qreal fileWriteDuration = time.restart(); |
104 | qreal fileWriteOpsPerMs = count / fileWriteDuration; | 104 | qreal fileWriteOpsPerMs = count / fileWriteDuration; |
105 | 105 | ||
106 | //Db read time | 106 | // Db read time |
107 | { | 107 | { |
108 | auto transaction = store->createTransaction(Sink::Storage::ReadOnly); | 108 | auto transaction = store->createTransaction(Sink::Storage::ReadOnly); |
109 | auto db = transaction.openDatabase(); | 109 | auto db = transaction.openDatabase(); |
@@ -127,10 +127,10 @@ private slots: | |||
127 | void testSizes() | 127 | void testSizes() |
128 | { | 128 | { |
129 | Sink::Storage store(testDataPath, dbName); | 129 | Sink::Storage store(testDataPath, dbName); |
130 | qDebug() << "Database size [kb]: " << store.diskUsage()/1024; | 130 | qDebug() << "Database size [kb]: " << store.diskUsage() / 1024; |
131 | 131 | ||
132 | QFileInfo fileInfo(filePath); | 132 | QFileInfo fileInfo(filePath); |
133 | qDebug() << "File size [kb]: " << fileInfo.size()/1024; | 133 | qDebug() << "File size [kb]: " << fileInfo.size() / 1024; |
134 | } | 134 | } |
135 | 135 | ||
136 | void testScan() | 136 | void testScan() |
@@ -139,13 +139,15 @@ private slots: | |||
139 | 139 | ||
140 | QBENCHMARK { | 140 | QBENCHMARK { |
141 | int hit = 0; | 141 | int hit = 0; |
142 | store->createTransaction(Sink::Storage::ReadOnly).openDatabase().scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { | 142 | store->createTransaction(Sink::Storage::ReadOnly) |
143 | if (key == "key10000") { | 143 | .openDatabase() |
144 | //qDebug() << "hit"; | 144 | .scan("", [&](const QByteArray &key, const QByteArray &value) -> bool { |
145 | hit++; | 145 | if (key == "key10000") { |
146 | } | 146 | // qDebug() << "hit"; |
147 | return true; | 147 | hit++; |
148 | }); | 148 | } |
149 | return true; | ||
150 | }); | ||
149 | QCOMPARE(hit, 1); | 151 | QCOMPARE(hit, 1); |
150 | } | 152 | } |
151 | } | 153 | } |