diff options
Diffstat (limited to 'buffertest/main.cpp')
-rw-r--r-- | buffertest/main.cpp | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/buffertest/main.cpp b/buffertest/main.cpp deleted file mode 100644 index 437e5b3..0000000 --- a/buffertest/main.cpp +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | #include "calendar_generated.h" | ||
2 | #include <iostream> | ||
3 | #include <fstream> | ||
4 | #include <QDir> | ||
5 | #include <QString> | ||
6 | #include <QTime> | ||
7 | #include <qdebug.h> | ||
8 | |||
9 | #include "store/database.h" | ||
10 | |||
11 | using namespace Calendar; | ||
12 | using namespace flatbuffers; | ||
13 | |||
14 | std::string createEvent(bool createAttachment = false) | ||
15 | { | ||
16 | FlatBufferBuilder fbb; | ||
17 | { | ||
18 | auto summary = fbb.CreateString("summary"); | ||
19 | |||
20 | // const int attachmentSize = 1024 * 1024; // 1MB | ||
21 | const int attachmentSize = 1024*2; // 1KB | ||
22 | int8_t rawData[attachmentSize]; | ||
23 | auto data = fbb.CreateVector(rawData, attachmentSize); | ||
24 | |||
25 | Calendar::EventBuilder eventBuilder(fbb); | ||
26 | eventBuilder.add_summary(summary); | ||
27 | eventBuilder.add_attachment(data); | ||
28 | auto eventLocation = eventBuilder.Finish(); | ||
29 | FinishEventBuffer(fbb, eventLocation); | ||
30 | } | ||
31 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
32 | } | ||
33 | |||
34 | void readEvent(const std::string &data) | ||
35 | { | ||
36 | auto readEvent = GetEvent(data.c_str()); | ||
37 | std::cout << readEvent->summary()->c_str() << std::endl; | ||
38 | } | ||
39 | |||
40 | int main(int argc, char **argv) | ||
41 | { | ||
42 | Database db; | ||
43 | const int count = 50000; | ||
44 | QTime time; | ||
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(); | ||
67 | } | ||