#include "catch/catch.hpp" #include "lib/jetfix/codec/Fields.h" #include "lib/jetfix/codec/Group.h" #include "lib/jetfix/codec/FIXMsg.h" #include "lib/jetfix/codec/FieldDefinitions.h" #include "lib/jetfix/connection/IConnectionObserver.h" #include "lib/jetfix/common/InMsgBuffer.h" #include "lib/jetfix/codec/FIXParser.h" #include "lib/jetfix/codec/FIXFragment.h" #include "lib/utils/TimeStamp.h" #include "lib/logging/logging.h" namespace bts { namespace jetfix { TEST_CASE ("JetFIX Performance Tests", "[jetfix] [benchmark]") { const char* mq_char = "8=FIX.4.2\001" "9=305\001" "35=i\001" "34=61\001" "49=1U7001N\001" "50=bluestream\001" "52=20150427-19:29:40.610\001" "56=CME\001" "57=G\001" "142=US,NC\001" "117=58\001" "204=1\001" "1028=N\001" "7928=bluestream\001" "9702=1\001" "9771=TESTACC\001" "296=1\001" "302=1\001" "304=2\001" "295=2\001" "299=10857\001" "55=EZ\001" "167=OPT\001" "107=ESK5 C1855\001" "132=25200\001" "133=25350\001" "134=1\001" "135=1\001" "299=10856\001" "55=EZ\001" "167=OPT\001" "107=ESK5 C1890\001" "132=25201\001" "133=25351\001" "134=2\001" "135=2\001" "10=002\001"; SECTION("decode_jetfix") { std::string mqs (mq_char); using namespace fix; typedef FIXMsg MassQuote; MassQuote mq; std::vector times; for (int i = 0; i < 10000;i++) { auto start = utils::TimeStamp::now (); mq.read (mqs); auto stop = utils::TimeStamp::now (); times.push_back ((stop-start).microseconds ()); } std::sort (times.begin (),times.end ()); LOG(Testing,Info,"decode_jetfix t: {}us", times[times.size ()/2] ); } SECTION("decode_with_parser") { auto fix = std::make_shared (mq_char); using namespace fix; typedef FIXMsg MassQuote; MassQuote mq; FIXParser parser; std::vector result; result.reserve (10000); std::vector times; for (int i = 0; i < 10000;i++) { auto start = utils::TimeStamp::now (); result.emplace_back (parser.parse (InMsgBuffer (fix->data (),fix->size (),fix))); auto stop = utils::TimeStamp::now (); times.push_back ((stop-start).microseconds ()); } std::sort (times.begin (),times.end ()); LOG(Testing,Info,"decode_with_parser t: {}us", times[times.size ()/2] ); } SECTION("encode_jetfix") { std::vector times; for (int i = 0; i < 1000;i++) { auto start = utils::TimeStamp::now (); for (int n = 0; n < 100;n++) { FIXFragment g; using namespace fix; g.add("58",sizeof("58")-1); g.add(1); g.add(true); g.add("bluestream",sizeof("bluestream")-1); g.add('1'); g.add("TESTACC",sizeof("TESTACC")-1); g.add(1); g.add("302",sizeof("302")-1); g.add(2); g.add (2); g.add("10857",sizeof("10857")-1); g.add("55",sizeof("55")-1); g.add("ESK5 C1855",sizeof("ESK5 C1855")-1); g.add("OPT",sizeof("OPT")-1); g.add(25200.0,-1,-1); g.add(1); g.add(25200.0,-1,-1); g.add(1); g.add("10857",sizeof("10857")-1); g.add("55",sizeof("55")-1); g.add("ESK5 C1855",sizeof("ESK5 C1855")-1); g.add("OPT",sizeof("OPT")-1); g.add(25200.0,-1,-1); g.add(1); g.add(25200.0,-1,-1); g.add(1); g.add(2,3); } auto stop = utils::TimeStamp::now (); times.push_back ((stop-start).microseconds ()); } std::sort (times.begin (),times.end ()); LOG(Testing,Info,"encode_jetfix t: {}us", times[times.size ()/2] / 100 ); } SECTION("templated_encoding") { using namespace fix; std::vector times; FIXFragment header; header.add("58",sizeof("58")-1); header.add(1); header.add(true); header.add("bluestream",sizeof("bluestream")-1); header.add('1'); header.add("TESTACC",sizeof("TESTACC")-1); header.add(1); header.add("302",sizeof("302")-1); FIXFragment qt1; auto qt1_quote_entry_id = qt1.add("10857",sizeof("10857")-1); qt1.add("55",sizeof("55")-1); qt1.add("ESK5 C1855",sizeof("ESK5 C1855")-1); qt1.add("OPT",sizeof("OPT")-1); auto qt1_bid_px = qt1.add(25200.0,-1,-1); auto qt1_bid_sz = qt1.add(1); auto qt1_offer_px = qt1.add(25200.0,-1,-1); auto qt1_offer_sz = qt1.add(1); FIXFragment qt2; auto qt2_quote_entry_id = qt2.add("10857",sizeof("10857")-1); qt2.add("55",sizeof("55")-1); qt2.add("ESK5 C1855",sizeof("ESK5 C1855")-1); qt2.add("OPT",sizeof("OPT")-1); auto qt2_bid_px = qt2.add(25200.0,-1,-1); auto qt2_bid_sz = qt2.add(1); auto qt2_offer_px = qt2.add(25200.0,-1,-1); auto qt2_offer_sz = qt2.add(1); FIXFragment g; for (int i = 0; i < 1000;i++) { auto start = utils::TimeStamp::now (); for (int n = 0; n < 100;n++) { g.reset (); g.append (header); g.add(2); g.add (2); qt1.overwrite (qt1_quote_entry_id,"10857",sizeof("10857")-1); qt1.overwrite (qt1_bid_px,25200.0,-1,-1); qt1.overwrite (qt1_bid_sz,1); qt1.overwrite (qt1_offer_px,25200.0,-1,-1); qt1.overwrite (qt1_offer_sz,1); g.append (qt1); qt2.overwrite (qt2_quote_entry_id,"10857",sizeof("10857")-1); qt2.overwrite (qt2_bid_px,25200.0,-1,-1); qt2.overwrite (qt2_bid_sz,1); qt2.overwrite (qt2_offer_px,25200.0,-1,-1); qt2.overwrite (qt2_offer_sz,1); g.append (qt2); g.add(2,3); } auto stop = utils::TimeStamp::now (); times.push_back ((stop-start).microseconds ()); } std::sort (times.begin (),times.end ()); LOG(Testing,Info,"templated_encoding t: {}us", times[times.size ()/2] / 100 ); } } }}