diff options
Diffstat (limited to 'buffertest/main.cpp')
-rw-r--r-- | buffertest/main.cpp | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/buffertest/main.cpp b/buffertest/main.cpp index 5bc2326..437e5b3 100644 --- a/buffertest/main.cpp +++ b/buffertest/main.cpp | |||
@@ -1,16 +1,24 @@ | |||
1 | #include "calendar_generated.h" | 1 | #include "calendar_generated.h" |
2 | #include <iostream> | 2 | #include <iostream> |
3 | #include <fstream> | 3 | #include <fstream> |
4 | #include <QDir> | ||
5 | #include <QString> | ||
6 | #include <QTime> | ||
7 | #include <qdebug.h> | ||
8 | |||
9 | #include "store/database.h" | ||
4 | 10 | ||
5 | using namespace Calendar; | 11 | using namespace Calendar; |
6 | using namespace flatbuffers; | 12 | using namespace flatbuffers; |
7 | 13 | ||
8 | std::string createEvent() | 14 | std::string createEvent(bool createAttachment = false) |
9 | { | 15 | { |
10 | FlatBufferBuilder fbb; | 16 | FlatBufferBuilder fbb; |
11 | { | 17 | { |
12 | auto summary = fbb.CreateString("summary"); | 18 | auto summary = fbb.CreateString("summary"); |
13 | const int attachmentSize = 1024 * 1024; // 1MB | 19 | |
20 | // const int attachmentSize = 1024 * 1024; // 1MB | ||
21 | const int attachmentSize = 1024*2; // 1KB | ||
14 | int8_t rawData[attachmentSize]; | 22 | int8_t rawData[attachmentSize]; |
15 | auto data = fbb.CreateVector(rawData, attachmentSize); | 23 | auto data = fbb.CreateVector(rawData, attachmentSize); |
16 | 24 | ||
@@ -31,8 +39,29 @@ void readEvent(const std::string &data) | |||
31 | 39 | ||
32 | int main(int argc, char **argv) | 40 | int main(int argc, char **argv) |
33 | { | 41 | { |
34 | std::ofstream myfile; | 42 | Database db; |
35 | myfile.open ("buffer.fb"); | 43 | const int count = 50000; |
36 | myfile << createEvent(); | 44 | QTime time; |
37 | myfile.close(); | 45 | time.start(); |
46 | // std::ofstream myfile; | ||
47 | // myfile.open ("buffer.fb"); | ||
48 | // | ||
49 | auto transaction = db.startTransaction(); | ||
50 | for (int i = 0; i < count; i++) { | ||
51 | const auto key = QString("key%1").arg(i); | ||
52 | auto event = createEvent(true); | ||
53 | db.write(key.toStdString(), event, transaction); | ||
54 | |||
55 | // myfile << createEvent(); | ||
56 | } | ||
57 | db.endTransaction(transaction); | ||
58 | // myfile.close(); | ||
59 | qDebug() << "Writing took: " << time.elapsed(); | ||
60 | |||
61 | time.start(); | ||
62 | for (int i = 0; i < count; i++) { | ||
63 | const auto key = QString("key%1").arg(i); | ||
64 | db.read(key.toStdString()); | ||
65 | } | ||
66 | qDebug() << "Reading took: " << time.elapsed(); | ||
38 | } | 67 | } |