Skip to content

Commit ddfeef4

Browse files
committed
compacted mode implemented in YAS & some optimisations in YAS & for tests ubuntu-14.04.3 + gcc-6.2.1 is used & graphs regenerated
1 parent 4fbd072 commit ddfeef4

File tree

9 files changed

+86
-69
lines changed

9 files changed

+86
-69
lines changed

CMakeLists.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ endif()
3131

3232
include_directories(${cpp_serializers_SOURCE_DIR})
3333

34-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W")
35-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W")
34+
set(CMAKE_C_COMPILER /usr/bin/gcc-6)
35+
set(CMAKE_CXX_COMPILER /usr/bin/g++-6)
36+
37+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wextra")
38+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wextra")
3639

3740
find_package(ZLIB)
3841
if (NOT ZLIB_FOUND)
@@ -196,8 +199,8 @@ set(yas_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/yas)
196199
ExternalProject_Add(
197200
yas
198201
PREFIX ${yas_PREFIX}
199-
URL "https://github.com/niXman/yas/archive/3.0.zip"
200-
URL_MD5 "906ac6654557052c6bfffbe7aa8024a8"
202+
URL "https://github.com/niXman/yas/archive/4.0.zip"
203+
URL_MD5 "7f9ed59c21020005046297934c196bd8"
201204
CONFIGURE_COMMAND ""
202205
BUILD_COMMAND ""
203206
INSTALL_COMMAND mkdir -p ${yas_PREFIX}/include/ && cp -r ${yas_PREFIX}/src/yas/include/yas ${yas_PREFIX}/include/

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ on a typical desktop computer with Intel Core i5 processor running Ubuntu 14.04.
5252
* avro 1.8.1
5353
* capnproto 0.5.3
5454
* flatbuffers 1.4.0
55-
* YAS 3.0.0
55+
* YAS 4.0.0
5656

5757
| serializer | object's size | avg. total time |
5858
| -------------- | ------------- | --------------- |
59-
| thrift-binary | 17017 | 13763 |
60-
| thrift-compact | 11597 | 27017 |
59+
| thrift-binary | 17017 | 22815 |
60+
| thrift-compact | 11597 | 26427 |
6161
| protobuf | 12571 | 21034 |
62-
| boost | 17470 | 22945 |
63-
| msgpack | 11902 | 23560 |
64-
| cereal | 17416 | 10688 |
65-
| avro | 12288 | 31750 |
66-
| YAS | 17015 | 4945 |
62+
| boost | 17470 | 22471 |
63+
| msgpack | 11902 | 25931 |
64+
| cereal | 17416 | 10304 |
65+
| avro | 12288 | 31658 |
66+
| yas | 17416 | 4044 |
67+
| yas-compact | 12830 | 21928 |
6768

6869
###### Size
6970

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

8081
| serializer | object's size | avg. total time |
8182
| -------------- | ------------- | --------------- |
82-
| capnproto | 17768 | 4396 |
83-
| flatbuffers | 17632 | 12494 |
83+
| capnproto | 17768 | 4259 |
84+
| flatbuffers | 17632 | 12762 |
8485

8586
![Time](images/time2.png)
8687

benchmark.cpp

+24-9
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ flatbuffers_serialization_test(size_t iterations)
471471
std::cout << "flatbuffers: time = " << duration << " milliseconds" << std::endl << std::endl;
472472
}
473473

474+
template<std::size_t opts>
474475
void
475476
yas_serialization_test(size_t iterations)
476477
{
@@ -488,30 +489,39 @@ yas_serialization_test(size_t iterations)
488489

489490
std::string serialized;
490491

491-
to_string(r1, serialized);
492-
from_string(r2, serialized);
492+
to_string<opts>(r1, serialized);
493+
from_string<opts>(r2, serialized);
493494

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

498-
std::cout << "yas: version = " << YAS_VERSION_STRING << std::endl;
499-
std::cout << "yas: size = " << serialized.size() << " bytes" << std::endl;
499+
if ( opts & yas::compacted ) {
500+
std::cout << "yas-compact: version = " << YAS_VERSION_STRING << std::endl;
501+
std::cout << "yas-compact: size = " << serialized.size() << " bytes" << std::endl;
502+
} else {
503+
std::cout << "yas: version = " << YAS_VERSION_STRING << std::endl;
504+
std::cout << "yas: size = " << serialized.size() << " bytes" << std::endl;
505+
}
500506

501507
auto start = std::chrono::high_resolution_clock::now();
502508
for (size_t i = 0; i < iterations; i++) {
503509
yas::mem_ostream os;
504-
yas::binary_oarchive<yas::mem_ostream, flags> oa(os);
510+
yas::binary_oarchive<yas::mem_ostream, opts> oa(os);
505511
oa & r1;
506512

507513
yas::mem_istream is(os.get_intrusive_buffer());
508-
yas::binary_iarchive<yas::mem_istream, flags> ia(is);
514+
yas::binary_iarchive<yas::mem_istream, opts> ia(is);
509515
ia & r2;
510516
}
511517
auto finish = std::chrono::high_resolution_clock::now();
512518
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
513519

514-
std::cout << "yas: time = " << duration << " milliseconds" << std::endl << std::endl;
520+
if ( opts & yas::compacted ) {
521+
std::cout << "yas-compact: time = " << duration << " milliseconds" << std::endl << std::endl;
522+
} else {
523+
std::cout << "yas: time = " << duration << " milliseconds" << std::endl << std::endl;
524+
}
515525
}
516526

517527
int
@@ -520,7 +530,7 @@ main(int argc, char **argv)
520530
GOOGLE_PROTOBUF_VERIFY_VERSION;
521531

522532
if (argc < 2) {
523-
std::cout << "usage: " << argv[0] << " N [thrift-binary thrift-compact protobuf boost msgpack cereal avro capnproto flatbuffers yas]";
533+
std::cout << "usage: " << argv[0] << " N [thrift-binary thrift-compact protobuf boost msgpack cereal avro capnproto flatbuffers yas yas-compact]";
524534
std::cout << std::endl << std::endl;
525535
std::cout << "arguments: " << std::endl;
526536
std::cout << " N -- number of iterations" << std::endl << std::endl;
@@ -585,8 +595,13 @@ main(int argc, char **argv)
585595
if (names.empty() || names.find("flatbuffers") != names.end()) {
586596
flatbuffers_serialization_test(iterations);
587597
}
598+
588599
if (names.empty() || names.find("yas") != names.end()) {
589-
yas_serialization_test(iterations);
600+
yas_serialization_test<yas::binary|yas::no_header>(iterations);
601+
}
602+
603+
if (names.empty() || names.find("yas-compact") != names.end()) {
604+
yas_serialization_test<yas::binary|yas::no_header|yas::compacted>(iterations);
590605
}
591606
} catch (std::exception &exc) {
592607
std::cerr << "Error: " << exc.what() << std::endl;

images/graphs.R

+28-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
library(ggplot2)
22

3-
names.size <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "capnproto", "flatbuffers", "yas")
4-
names.time <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "yas")
3+
names.size <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "capnproto", "flatbuffers", "yas", "yas-compact")
4+
names.time <- c("thrift-binary", "thrift-compact", "protobuf", "boost", "msgpack", "cereal", "avro", "yas", "yas-compact")
55
names.time2 <- c("capnproto", "flatbuffers")
66
# data from the 1000000 simulations
7-
# 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
7+
# 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
88
size <- c(
9-
17017
10-
,11597
11-
,11574
12-
,17470
13-
,11802
14-
,17416
15-
,12288
16-
,17768
17-
,17632
18-
,17015
9+
17017 # thrift-binary
10+
,11597 # thrift-compact
11+
,11574 # protobuf
12+
,17470 # boost
13+
,11802 # msgpack
14+
,17416 # cereal
15+
,12288 # avro
16+
,17768 # capnproto
17+
,17632 # flatbuffers
18+
,17416 # yas
19+
,12830 # yas-compact
1920
)
20-
# 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
21+
# 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
2122
time <- c(
22-
13179 # thrift-binary
23-
,25562 # thrift-compact
24-
,22468 # protobuf
25-
,21405 # boost
26-
,27805 # msgpack
27-
,10654 # cereal
28-
,31231 # avro
29-
,4945 # yas
23+
22815 # thrift-binary
24+
,26427 # thrift-compact
25+
,22471 # protobuf
26+
,12272 # boost
27+
,25931 # msgpack
28+
,10304 # cereal
29+
,31658 # avro
30+
,4044 # yas
31+
,21928 # yas-compact
32+
)
33+
time2 <- c(
34+
4259 # capnproto
35+
,12762 # flatbuffers
3036
)
31-
time2 <- c(4396, 12494)
3237

3338
data.size <- as.data.frame(list(serializer = names.size, size = size))
3439
data.time <- as.data.frame(list(serializer = names.time, time = time))

images/size.png

1.84 KB
Loading

images/time.png

1.95 KB
Loading

images/time2.png

-8 Bytes
Loading

yas/record.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,4 @@
33

44
namespace yas_test {
55

6-
void
7-
to_string(const Record &record, std::string &data)
8-
{
9-
yas::mem_ostream os;
10-
yas::binary_oarchive<yas::mem_ostream, flags> oa(os);
11-
oa & record;
12-
13-
auto buf = os.get_intrusive_buffer();
14-
data.assign(buf.data, buf.size);
15-
}
16-
17-
void
18-
from_string(Record &record, const std::string &data)
19-
{
20-
yas::mem_istream is(data.c_str(), data.size());
21-
yas::binary_iarchive<yas::mem_istream, flags> ia(is);
22-
ia & record;
23-
}
24-
256
} // namespace

yas/record.hpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
namespace yas_test {
1616

17-
enum { flags = yas::binary|yas::no_header|yas::seq_size_32 };
18-
1917
typedef std::vector<int64_t> Integers;
2018
typedef std::vector<std::string> Strings;
2119

@@ -39,8 +37,22 @@ struct Record {
3937
}
4038
};
4139

42-
void to_string(const Record &record, std::string &data);
43-
void from_string(Record &record, const std::string &data);
40+
template<std::size_t opts>
41+
void to_string(const Record &record, std::string &data) {
42+
yas::mem_ostream os;
43+
yas::binary_oarchive<yas::mem_ostream, opts> oa(os);
44+
oa & record;
45+
46+
auto buf = os.get_intrusive_buffer();
47+
data.assign(buf.data, buf.size);
48+
}
49+
50+
template<std::size_t opts>
51+
void from_string(Record &record, const std::string &data) {
52+
yas::mem_istream is(data.c_str(), data.size());
53+
yas::binary_iarchive<yas::mem_istream, opts> ia(is);
54+
ia & record;
55+
}
4456

4557
} // namespace
4658

0 commit comments

Comments
 (0)