summaryrefslogtreecommitdiffstats
path: root/tests/storagebenchmark.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-12-06 02:22:51 +0100
committerAaron Seigo <aseigo@kde.org>2014-12-06 02:22:51 +0100
commit165312053bec1d36b161088258e97cf2eaa1ca54 (patch)
tree4f1010eb6e5cdb074e746f65000a8c254c87a665 /tests/storagebenchmark.cpp
parent0818f3de0fe44ad53358fafd57c6d7dea729d319 (diff)
downloadsink-165312053bec1d36b161088258e97cf2eaa1ca54.tar.gz
sink-165312053bec1d36b161088258e97cf2eaa1ca54.zip
make this 2 orders of magnitude faster by using uninitialized vectors
Diffstat (limited to 'tests/storagebenchmark.cpp')
-rw-r--r--tests/storagebenchmark.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp
index 9c95d3b..f05cc78 100644
--- a/tests/storagebenchmark.cpp
+++ b/tests/storagebenchmark.cpp
@@ -16,20 +16,22 @@ using namespace flatbuffers;
16 16
17static std::string createEvent() 17static std::string createEvent()
18{ 18{
19 FlatBufferBuilder fbb; 19 static const size_t attachmentSize = 1024*2; // 2KB
20 static uint8_t rawData[attachmentSize];
21 static FlatBufferBuilder fbb;
22 fbb.Clear();
20 { 23 {
21 auto summary = fbb.CreateString("summary"); 24 auto summary = fbb.CreateString("summary");
22 25 auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize);
23 const int attachmentSize = 1024*2; // 2KB 26 //auto data = fbb.CreateVector(rawData, attachmentSize);
24 int8_t rawData[attachmentSize];
25 auto data = fbb.CreateVector(rawData, attachmentSize);
26
27 Calendar::EventBuilder eventBuilder(fbb); 27 Calendar::EventBuilder eventBuilder(fbb);
28 eventBuilder.add_summary(summary); 28 eventBuilder.add_summary(summary);
29 eventBuilder.add_attachment(data); 29 eventBuilder.add_attachment(data);
30 auto eventLocation = eventBuilder.Finish(); 30 auto eventLocation = eventBuilder.Finish();
31 FinishEventBuffer(fbb, eventLocation); 31 Calendar::FinishEventBuffer(fbb, eventLocation);
32 memcpy((void*)Calendar::GetEvent(fbb.GetBufferPointer())->attachment()->Data(), rawData, attachmentSize);
32 } 33 }
34
33 return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); 35 return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
34} 36}
35 37