Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ endif()

include_directories(${cpp_serializers_SOURCE_DIR})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wextra")

find_package(ZLIB)
if (NOT ZLIB_FOUND)
Expand Down Expand Up @@ -196,8 +196,8 @@ set(yas_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/yas)
ExternalProject_Add(
yas
PREFIX ${yas_PREFIX}
URL "https://github.com/niXman/yas/archive/3.0.zip"
URL_MD5 "906ac6654557052c6bfffbe7aa8024a8"
URL "https://github.com/niXman/yas/archive/4.0.zip"
URL_MD5 "7f9ed59c21020005046297934c196bd8"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND mkdir -p ${yas_PREFIX}/include/ && cp -r ${yas_PREFIX}/src/yas/include/yas ${yas_PREFIX}/include/
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@ on a typical desktop computer with Intel Core i5 processor running Ubuntu 14.04.
* avro 1.8.1
* capnproto 0.5.3
* flatbuffers 1.4.0
* YAS 3.0.0
* YAS 4.0.0

| serializer | object's size | avg. total time |
| -------------- | ------------- | --------------- |
| thrift-binary | 17017 | 13763 |
| thrift-compact | 11597 | 27017 |
| protobuf | 12571 | 21034 |
| boost | 17470 | 22945 |
| msgpack | 11902 | 23560 |
| cereal | 17416 | 10688 |
| avro | 12288 | 31750 |
| YAS | 17015 | 4945 |
| thrift-binary | 17017 | 13748 |
| thrift-compact | 11597 | 25947 |
| protobuf | 12571 | 24196 |
| boost | 17470 | 21717 |
| msgpack | 11902 | 29597 |
| cereal | 17416 | 11121 |
| avro | 12288 | 31880 |
| yas | 17416 | 5113 |
| yas-compact | 12830 | 21858 |

###### Size

Expand All @@ -79,8 +80,8 @@ serialize/deserialize cycle of the already built data structure.

| serializer | object's size | avg. total time |
| -------------- | ------------- | --------------- |
| capnproto | 17768 | 4396 |
| flatbuffers | 17632 | 12494 |
| capnproto | 17768 | 4460 |
| flatbuffers | 17632 | 12755 |

![Time](images/time2.png)

Expand Down
33 changes: 24 additions & 9 deletions benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ flatbuffers_serialization_test(size_t iterations)
std::cout << "flatbuffers: time = " << duration << " milliseconds" << std::endl << std::endl;
}

template<std::size_t opts>
void
yas_serialization_test(size_t iterations)
{
Expand All @@ -488,30 +489,39 @@ yas_serialization_test(size_t iterations)

std::string serialized;

to_string(r1, serialized);
from_string(r2, serialized);
to_string<opts>(r1, serialized);
from_string<opts>(r2, serialized);

if (r1 != r2) {
throw std::logic_error("yas' case: deserialization failed");
}

std::cout << "yas: version = " << YAS_VERSION_STRING << std::endl;
std::cout << "yas: size = " << serialized.size() << " bytes" << std::endl;
if ( opts & yas::compacted ) {
std::cout << "yas-compact: version = " << YAS_VERSION_STRING << std::endl;
std::cout << "yas-compact: size = " << serialized.size() << " bytes" << std::endl;
} else {
std::cout << "yas: version = " << YAS_VERSION_STRING << std::endl;
std::cout << "yas: size = " << serialized.size() << " bytes" << std::endl;
}

auto start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < iterations; i++) {
yas::mem_ostream os;
yas::binary_oarchive<yas::mem_ostream, flags> oa(os);
yas::binary_oarchive<yas::mem_ostream, opts> oa(os);
oa & r1;

yas::mem_istream is(os.get_intrusive_buffer());
yas::binary_iarchive<yas::mem_istream, flags> ia(is);
yas::binary_iarchive<yas::mem_istream, opts> ia(is);
ia & r2;
}
auto finish = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();

std::cout << "yas: time = " << duration << " milliseconds" << std::endl << std::endl;
if ( opts & yas::compacted ) {
std::cout << "yas-compact: time = " << duration << " milliseconds" << std::endl << std::endl;
} else {
std::cout << "yas: time = " << duration << " milliseconds" << std::endl << std::endl;
}
}

int
Expand All @@ -520,7 +530,7 @@ main(int argc, char **argv)
GOOGLE_PROTOBUF_VERIFY_VERSION;

if (argc < 2) {
std::cout << "usage: " << argv[0] << " N [thrift-binary thrift-compact protobuf boost msgpack cereal avro capnproto flatbuffers yas]";
std::cout << "usage: " << argv[0] << " N [thrift-binary thrift-compact protobuf boost msgpack cereal avro capnproto flatbuffers yas yas-compact]";
std::cout << std::endl << std::endl;
std::cout << "arguments: " << std::endl;
std::cout << " N -- number of iterations" << std::endl << std::endl;
Expand Down Expand Up @@ -585,8 +595,13 @@ main(int argc, char **argv)
if (names.empty() || names.find("flatbuffers") != names.end()) {
flatbuffers_serialization_test(iterations);
}

if (names.empty() || names.find("yas") != names.end()) {
yas_serialization_test(iterations);
yas_serialization_test<yas::binary|yas::no_header>(iterations);
}

if (names.empty() || names.find("yas-compact") != names.end()) {
yas_serialization_test<yas::binary|yas::no_header|yas::compacted>(iterations);
}
} catch (std::exception &exc) {
std::cerr << "Error: " << exc.what() << std::endl;
Expand Down
51 changes: 28 additions & 23 deletions images/graphs.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
library(ggplot2)

names.size <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "capnproto", "flatbuffers", "yas")
names.time <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "yas")
names.size <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "capnproto", "flatbuffers", "yas", "yas-compact")
names.time <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "yas", "yas-compact")
names.time2 <- c("capnproto", "flatbuffers")
# data from the 1000000 simulations
# for t in thrift-binary thrift-compact protobuf boost msgpack cereal avro yas; do echo -n "$t: "; ./benchmark 1 $t | grep size | awk '{print $4}'; done
# for t in thrift-binary thrift-compact protobuf boost msgpack cereal avro yas yas-compact; do echo -n "$t: "; ./benchmark 1 $t | grep size | awk '{print $4}'; done
size <- c(
17017
,11597
,11574
,17470
,11802
,17416
,12288
,17768
,17632
,17015
17017 # thrift-binary
,11597 # thrift-compact
,11574 # protobuf
,17470 # boost
,11802 # msgpack
,17416 # cereal
,12288 # avro
,17768 # capnproto
,17632 # flatbuffers
,17416 # yas
,12830 # yas-compact
)
# for t in thrift-binary thrift-compact protobuf boost msgpack cereal avro yas; do rm -f /tmp/$t.time; echo -n "$t: "; for i in `seq 1 50`; do ./benchmark 1000000 $t | grep time | awk '{print $4}' >>/tmp/$t.time; done; awk '{ sum += $1 } END { print sum/50}' /tmp/$t.time; done
# for t in thrift-binary thrift-compact protobuf boost msgpack cereal avro yas yas-compact; do rm -f /tmp/$t.time; echo -n "$t: "; for i in `seq 1 50`; do ./benchmark 1000000 $t | grep time | awk '{print $4}' >>/tmp/$t.time; done; awk '{ sum += $1 } END { print sum/50}' /tmp/$t.time; done
time <- c(
13179 # thrift-binary
,25562 # thrift-compact
,22468 # protobuf
,21405 # boost
,27805 # msgpack
,10654 # cereal
,31231 # avro
,4945 # yas
13748 # thrift-binary
,25947 # thrift-compact
,24196 # protobuf
,21717 # boost
,29597 # msgpack
,11121 # cereal
,31880 # avro
,5113 # yas
,21858 # yas-compact
)
time2 <- c(
4460 # capnproto
,12755 # flatbuffers
)
time2 <- c(4396, 12494)

data.size <- as.data.frame(list(serializer = names.size, size = size))
data.time <- as.data.frame(list(serializer = names.time, time = time))
Expand Down
Binary file modified images/size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/time2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions yas/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,4 @@

namespace yas_test {

void
to_string(const Record &record, std::string &data)
{
yas::mem_ostream os;
yas::binary_oarchive<yas::mem_ostream, flags> oa(os);
oa & record;

auto buf = os.get_intrusive_buffer();
data.assign(buf.data, buf.size);
}

void
from_string(Record &record, const std::string &data)
{
yas::mem_istream is(data.c_str(), data.size());
yas::binary_iarchive<yas::mem_istream, flags> ia(is);
ia & record;
}

} // namespace
20 changes: 16 additions & 4 deletions yas/record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

namespace yas_test {

enum { flags = yas::binary|yas::no_header|yas::seq_size_32 };

typedef std::vector<int64_t> Integers;
typedef std::vector<std::string> Strings;

Expand All @@ -39,8 +37,22 @@ struct Record {
}
};

void to_string(const Record &record, std::string &data);
void from_string(Record &record, const std::string &data);
template<std::size_t opts>
void to_string(const Record &record, std::string &data) {
yas::mem_ostream os;
yas::binary_oarchive<yas::mem_ostream, opts> oa(os);
oa & record;

auto buf = os.get_intrusive_buffer();
data.assign(buf.data, buf.size);
}

template<std::size_t opts>
void from_string(Record &record, const std::string &data) {
yas::mem_istream is(data.c_str(), data.size());
yas::binary_iarchive<yas::mem_istream, opts> ia(is);
ia & record;
}

} // namespace

Expand Down