diff options
-rw-r--r-- | store/test/storagebenchmark.cpp | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/store/test/storagebenchmark.cpp b/store/test/storagebenchmark.cpp index 939ae0b..6fc50f6 100644 --- a/store/test/storagebenchmark.cpp +++ b/store/test/storagebenchmark.cpp | |||
@@ -32,11 +32,11 @@ static std::string createEvent() | |||
32 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | 32 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); |
33 | } | 33 | } |
34 | 34 | ||
35 | static void readEvent(const std::string &data) | 35 | // static void readEvent(const std::string &data) |
36 | { | 36 | // { |
37 | auto readEvent = GetEvent(data.c_str()); | 37 | // auto readEvent = GetEvent(data.c_str()); |
38 | std::cout << readEvent->summary()->c_str() << std::endl; | 38 | // std::cout << readEvent->summary()->c_str() << std::endl; |
39 | } | 39 | // } |
40 | 40 | ||
41 | class StorageBenchmark : public QObject | 41 | class StorageBenchmark : public QObject |
42 | { | 42 | { |
@@ -46,6 +46,7 @@ private: | |||
46 | QString testDataPath; | 46 | QString testDataPath; |
47 | QString dbPath; | 47 | QString dbPath; |
48 | QString filePath; | 48 | QString filePath; |
49 | const int count = 50000; | ||
49 | 50 | ||
50 | private Q_SLOTS: | 51 | private Q_SLOTS: |
51 | void initTestCase() | 52 | void initTestCase() |
@@ -65,7 +66,6 @@ private Q_SLOTS: | |||
65 | QTest::addColumn<bool>("useDb"); | 66 | QTest::addColumn<bool>("useDb"); |
66 | QTest::addColumn<int>("count"); | 67 | QTest::addColumn<int>("count"); |
67 | 68 | ||
68 | const int count = 50000; | ||
69 | QTest::newRow("db, 50k") << true << count; | 69 | QTest::newRow("db, 50k") << true << count; |
70 | QTest::newRow("file, 50k") << false << count; | 70 | QTest::newRow("file, 50k") << false << count; |
71 | } | 71 | } |
@@ -79,16 +79,21 @@ private Q_SLOTS: | |||
79 | 79 | ||
80 | std::ofstream myfile; | 80 | std::ofstream myfile; |
81 | myfile.open(filePath.toStdString()); | 81 | myfile.open(filePath.toStdString()); |
82 | const char *keyPrefix = "key"; | ||
82 | 83 | ||
83 | QTime time; | 84 | QTime time; |
85 | |||
84 | time.start(); | 86 | time.start(); |
85 | { | 87 | { |
86 | auto transaction = db.startTransaction(); | 88 | auto transaction = db.startTransaction(); |
89 | auto event = createEvent(); | ||
87 | for (int i = 0; i < count; i++) { | 90 | for (int i = 0; i < count; i++) { |
88 | const auto key = QString("key%1").arg(i); | 91 | if (useDb && i > 0 && (i % 10000 == 0)) { |
89 | auto event = createEvent(); | 92 | db.endTransaction(transaction); |
93 | transaction = db.startTransaction(); | ||
94 | } | ||
90 | if (useDb) { | 95 | if (useDb) { |
91 | db.write(key.toStdString(), event, transaction); | 96 | db.write(keyPrefix + std::to_string(i), event, transaction); |
92 | } else { | 97 | } else { |
93 | myfile << event; | 98 | myfile << event; |
94 | } | 99 | } |
@@ -105,13 +110,13 @@ private Q_SLOTS: | |||
105 | time.start(); | 110 | time.start(); |
106 | { | 111 | { |
107 | for (int i = 0; i < count; i++) { | 112 | for (int i = 0; i < count; i++) { |
108 | const auto key = QString("key%1").arg(i); | ||
109 | if (useDb) { | 113 | if (useDb) { |
110 | db.read(key.toStdString()); | 114 | db.read(keyPrefix + std::to_string(i)); |
111 | } | 115 | } |
112 | } | 116 | } |
113 | } | 117 | } |
114 | const int readDuration = time.elapsed(); | 118 | const int readDuration = time.elapsed(); |
119 | |||
115 | if (useDb) { | 120 | if (useDb) { |
116 | qDebug() << "Reading took[ms]: " << readDuration; | 121 | qDebug() << "Reading took[ms]: " << readDuration; |
117 | } else { | 122 | } else { |
@@ -119,6 +124,20 @@ private Q_SLOTS: | |||
119 | } | 124 | } |
120 | } | 125 | } |
121 | 126 | ||
127 | void testBufferCreation() | ||
128 | { | ||
129 | QTime time; | ||
130 | |||
131 | time.start(); | ||
132 | { | ||
133 | for (int i = 0; i < count; i++) { | ||
134 | auto event = createEvent(); | ||
135 | } | ||
136 | } | ||
137 | const int bufferDuration = time.elapsed(); | ||
138 | qDebug() << "Creating buffers took[ms]: " << bufferDuration; | ||
139 | } | ||
140 | |||
122 | void testSizes() | 141 | void testSizes() |
123 | { | 142 | { |
124 | QFileInfo dbInfo(dbPath, "data.mdb"); | 143 | QFileInfo dbInfo(dbPath, "data.mdb"); |