diff options
Diffstat (limited to 'store/test/storagebenchmark.cpp')
-rw-r--r-- | store/test/storagebenchmark.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
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 @@ | |||
1 | #include <QtTest> | 1 | #include <QtTest> |
2 | 2 | ||
3 | #include "calendar_generated.h" | 3 | #include "calendar_generated.h" |
4 | |||
4 | #include <iostream> | 5 | #include <iostream> |
5 | #include <fstream> | 6 | #include <fstream> |
7 | |||
8 | #include <QDebug> | ||
6 | #include <QDir> | 9 | #include <QDir> |
7 | #include <QString> | 10 | #include <QString> |
8 | #include <QTime> | 11 | #include <QTime> |
9 | #include <qdebug.h> | ||
10 | 12 | ||
11 | #include "store/database.h" | 13 | #include "store/database.h" |
12 | 14 | ||
@@ -75,7 +77,10 @@ private Q_SLOTS: | |||
75 | QFETCH(bool, useDb); | 77 | QFETCH(bool, useDb); |
76 | QFETCH(int, count); | 78 | QFETCH(int, count); |
77 | 79 | ||
78 | Database db(dbPath); | 80 | Database *db = 0; |
81 | if (useDb) { | ||
82 | db = new Database(dbPath); | ||
83 | } | ||
79 | 84 | ||
80 | std::ofstream myfile; | 85 | std::ofstream myfile; |
81 | myfile.open(filePath.toStdString()); | 86 | myfile.open(filePath.toStdString()); |
@@ -85,21 +90,22 @@ private Q_SLOTS: | |||
85 | 90 | ||
86 | time.start(); | 91 | time.start(); |
87 | { | 92 | { |
88 | auto transaction = db.startTransaction(); | ||
89 | auto event = createEvent(); | 93 | auto event = createEvent(); |
90 | for (int i = 0; i < count; i++) { | 94 | for (int i = 0; i < count; i++) { |
91 | if (useDb && i > 0 && (i % 10000 == 0)) { | 95 | if (db) { |
92 | db.endTransaction(transaction); | 96 | if (i % 10000 == 0) { |
93 | transaction = db.startTransaction(); | 97 | db->commitTransaction(); |
94 | } | 98 | db->startTransaction(); |
95 | if (useDb) { | 99 | } |
96 | db.write(keyPrefix + std::to_string(i), event, transaction); | 100 | |
101 | db->write(keyPrefix + std::to_string(i), event); | ||
97 | } else { | 102 | } else { |
98 | myfile << event; | 103 | myfile << event; |
99 | } | 104 | } |
100 | } | 105 | } |
101 | if (useDb) { | 106 | |
102 | db.endTransaction(transaction); | 107 | if (db) { |
108 | db->commitTransaction(); | ||
103 | } else { | 109 | } else { |
104 | myfile.close(); | 110 | myfile.close(); |
105 | } | 111 | } |
@@ -110,8 +116,8 @@ private Q_SLOTS: | |||
110 | time.start(); | 116 | time.start(); |
111 | { | 117 | { |
112 | for (int i = 0; i < count; i++) { | 118 | for (int i = 0; i < count; i++) { |
113 | if (useDb) { | 119 | if (db) { |
114 | db.read(keyPrefix + std::to_string(i)); | 120 | db->read(keyPrefix + std::to_string(i), [](void *ptr, int size){}); |
115 | } | 121 | } |
116 | } | 122 | } |
117 | } | 123 | } |