diff options
Diffstat (limited to 'buffertest')
-rw-r--r-- | buffertest/CMakeLists.txt | 30 | ||||
-rw-r--r-- | buffertest/calendar.fbs | 12 | ||||
-rw-r--r-- | buffertest/main.cpp | 67 |
3 files changed, 0 insertions, 109 deletions
diff --git a/buffertest/CMakeLists.txt b/buffertest/CMakeLists.txt deleted file mode 100644 index fd100d0..0000000 --- a/buffertest/CMakeLists.txt +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | project(toynadi_buffertest) | ||
2 | |||
3 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | ||
4 | |||
5 | set(store_path "../store/") | ||
6 | |||
7 | set(toynadinbuffertest_SRCS | ||
8 | ${store_path}/database.cpp | ||
9 | main.cpp | ||
10 | ) | ||
11 | |||
12 | set(SCHEMAS calendar.fbs) | ||
13 | set(SCHEMA_SOURCEFILES calendar_generated.h) | ||
14 | |||
15 | add_custom_command(OUTPUT ${SCHEMA_SOURCEFILES} | ||
16 | COMMAND flatc -c ${CMAKE_CURRENT_SOURCE_DIR}/calendar.fbs | ||
17 | COMMENT "Generating buffers" | ||
18 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
19 | DEPENDS ${SCHEMAS} | ||
20 | VERBATIM | ||
21 | ) | ||
22 | |||
23 | SET_SOURCE_FILES_PROPERTIES(${SCHEMA_SOURCEFILES} PROPERTIES GENERATED 1) | ||
24 | ADD_CUSTOM_TARGET(generate_buffers ALL DEPENDS ${SCHEMA_SOURCEFILES}) | ||
25 | |||
26 | add_executable(${PROJECT_NAME} ${toynadinbuffertest_SRCS}) | ||
27 | qt5_use_modules(${PROJECT_NAME} Core) | ||
28 | target_link_libraries(${PROJECT_NAME} lmdb) | ||
29 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) | ||
30 | |||
diff --git a/buffertest/calendar.fbs b/buffertest/calendar.fbs deleted file mode 100644 index 203ee43..0000000 --- a/buffertest/calendar.fbs +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | // example IDL file | ||
2 | |||
3 | namespace Calendar; | ||
4 | |||
5 | table Event { | ||
6 | summary:string; | ||
7 | description:string; | ||
8 | attachment:[byte]; | ||
9 | } | ||
10 | |||
11 | root_type Event; | ||
12 | file_identifier "AKFB"; | ||
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 | } | ||