blob: 437e5b3d23ba2b49c64ef51fd5c9ccb839c126e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#include "calendar_generated.h"
#include <iostream>
#include <fstream>
#include <QDir>
#include <QString>
#include <QTime>
#include <qdebug.h>
#include "store/database.h"
using namespace Calendar;
using namespace flatbuffers;
std::string createEvent(bool createAttachment = false)
{
FlatBufferBuilder fbb;
{
auto summary = fbb.CreateString("summary");
// const int attachmentSize = 1024 * 1024; // 1MB
const int attachmentSize = 1024*2; // 1KB
int8_t rawData[attachmentSize];
auto data = fbb.CreateVector(rawData, attachmentSize);
Calendar::EventBuilder eventBuilder(fbb);
eventBuilder.add_summary(summary);
eventBuilder.add_attachment(data);
auto eventLocation = eventBuilder.Finish();
FinishEventBuffer(fbb, eventLocation);
}
return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
}
void readEvent(const std::string &data)
{
auto readEvent = GetEvent(data.c_str());
std::cout << readEvent->summary()->c_str() << std::endl;
}
int main(int argc, char **argv)
{
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();
}
|