From 64e82fe5ccfa10e1652c149d10e89b08a5aae165 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 22 Nov 2014 12:05:52 +0100 Subject: Buffertest + store --- buffertest/CMakeLists.txt | 4 ++++ buffertest/main.cpp | 41 +++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'buffertest') diff --git a/buffertest/CMakeLists.txt b/buffertest/CMakeLists.txt index 9505b75..fd100d0 100644 --- a/buffertest/CMakeLists.txt +++ b/buffertest/CMakeLists.txt @@ -2,7 +2,10 @@ project(toynadi_buffertest) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +set(store_path "../store/") + set(toynadinbuffertest_SRCS + ${store_path}/database.cpp main.cpp ) @@ -22,5 +25,6 @@ ADD_CUSTOM_TARGET(generate_buffers ALL DEPENDS ${SCHEMA_SOURCEFILES}) add_executable(${PROJECT_NAME} ${toynadinbuffertest_SRCS}) qt5_use_modules(${PROJECT_NAME} Core) +target_link_libraries(${PROJECT_NAME} lmdb) install(TARGETS ${PROJECT_NAME} DESTINATION bin) 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 @@ #include "calendar_generated.h" #include #include +#include +#include +#include +#include + +#include "store/database.h" using namespace Calendar; using namespace flatbuffers; -std::string createEvent() +std::string createEvent(bool createAttachment = false) { FlatBufferBuilder fbb; { auto summary = fbb.CreateString("summary"); - const int attachmentSize = 1024 * 1024; // 1MB + + // const int attachmentSize = 1024 * 1024; // 1MB + const int attachmentSize = 1024*2; // 1KB int8_t rawData[attachmentSize]; auto data = fbb.CreateVector(rawData, attachmentSize); @@ -31,8 +39,29 @@ void readEvent(const std::string &data) int main(int argc, char **argv) { - std::ofstream myfile; - myfile.open ("buffer.fb"); - myfile << createEvent(); - myfile.close(); + Database db; + const int count = 50000; + QTime time; + time.start(); + // std::ofstream myfile; + // myfile.open ("buffer.fb"); + // + auto transaction = db.startTransaction(); + for (int i = 0; i < count; i++) { + const auto key = QString("key%1").arg(i); + auto event = createEvent(true); + db.write(key.toStdString(), event, transaction); + + // myfile << createEvent(); + } + db.endTransaction(transaction); + // myfile.close(); + qDebug() << "Writing took: " << time.elapsed(); + + time.start(); + for (int i = 0; i < count; i++) { + const auto key = QString("key%1").arg(i); + db.read(key.toStdString()); + } + qDebug() << "Reading took: " << time.elapsed(); } -- cgit v1.2.3