264 lines
8.2 KiB
C++
264 lines
8.2 KiB
C++
#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<MessageTypes::MassQuote,
|
|
BeginString,
|
|
BodyLength,
|
|
MsgType,
|
|
MsgSeqNum,
|
|
SenderCompID,
|
|
SenderSubID,
|
|
SendingTime,
|
|
TargetCompId,
|
|
TargetSubID,
|
|
SenderLocationID,
|
|
QuoteID,
|
|
CustomerOrFirm,
|
|
ManualOrderIndicator,
|
|
SelfMatchPreventionID,
|
|
CtiCode,
|
|
MMAccount,
|
|
QuoteSets,
|
|
Checksum> MassQuote;
|
|
MassQuote mq;
|
|
|
|
std::vector<double> 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<std::string> (mq_char);
|
|
|
|
using namespace fix;
|
|
typedef FIXMsg<MessageTypes::MassQuote,
|
|
BeginString,
|
|
BodyLength,
|
|
MsgType,
|
|
MsgSeqNum,
|
|
SenderCompID,
|
|
SenderSubID,
|
|
SendingTime,
|
|
TargetCompId,
|
|
TargetSubID,
|
|
SenderLocationID,
|
|
QuoteID,
|
|
CustomerOrFirm,
|
|
ManualOrderIndicator,
|
|
SelfMatchPreventionID,
|
|
CtiCode,
|
|
MMAccount,
|
|
QuoteSets,
|
|
Checksum> MassQuote;
|
|
MassQuote mq;
|
|
FIXParser<MassQuote> parser;
|
|
std::vector<IFIXMsgPtr> result;
|
|
result.reserve (10000);
|
|
|
|
std::vector<double> 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<double> 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<QuoteID>("58",sizeof("58")-1);
|
|
g.add<CustomerOrFirm>(1);
|
|
g.add<ManualOrderIndicator>(true);
|
|
g.add<SelfMatchPreventionID>("bluestream",sizeof("bluestream")-1);
|
|
g.add<CtiCode>('1');
|
|
g.add<MMAccount>("TESTACC",sizeof("TESTACC")-1);
|
|
|
|
g.add<NoQuoteSets>(1);
|
|
g.add<QuoteSetID>("302",sizeof("302")-1);
|
|
g.add<TotQuoteEntries>(2);
|
|
|
|
g.add<NoQuoteEntries> (2);
|
|
|
|
g.add<QuoteEntryID>("10857",sizeof("10857")-1);
|
|
g.add<Symbol>("55",sizeof("55")-1);
|
|
g.add<SecurityDesc>("ESK5 C1855",sizeof("ESK5 C1855")-1);
|
|
g.add<SecurityType>("OPT",sizeof("OPT")-1);
|
|
g.add<BidPx>(25200.0,-1,-1);
|
|
g.add<BidSize>(1);
|
|
g.add<OfferPx>(25200.0,-1,-1);
|
|
g.add<OfferSize>(1);
|
|
|
|
g.add<QuoteEntryID>("10857",sizeof("10857")-1);
|
|
g.add<Symbol>("55",sizeof("55")-1);
|
|
g.add<SecurityDesc>("ESK5 C1855",sizeof("ESK5 C1855")-1);
|
|
g.add<SecurityType>("OPT",sizeof("OPT")-1);
|
|
g.add<BidPx>(25200.0,-1,-1);
|
|
g.add<BidSize>(1);
|
|
g.add<OfferPx>(25200.0,-1,-1);
|
|
g.add<OfferSize>(1);
|
|
|
|
g.add<Checksum>(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<double> times;
|
|
FIXFragment header;
|
|
header.add<QuoteID>("58",sizeof("58")-1);
|
|
header.add<CustomerOrFirm>(1);
|
|
header.add<ManualOrderIndicator>(true);
|
|
header.add<SelfMatchPreventionID>("bluestream",sizeof("bluestream")-1);
|
|
header.add<CtiCode>('1');
|
|
header.add<MMAccount>("TESTACC",sizeof("TESTACC")-1);
|
|
header.add<NoQuoteSets>(1);
|
|
header.add<QuoteSetID>("302",sizeof("302")-1);
|
|
|
|
FIXFragment qt1;
|
|
auto qt1_quote_entry_id = qt1.add<QuoteEntryID>("10857",sizeof("10857")-1);
|
|
qt1.add<Symbol>("55",sizeof("55")-1);
|
|
qt1.add<SecurityDesc>("ESK5 C1855",sizeof("ESK5 C1855")-1);
|
|
qt1.add<SecurityType>("OPT",sizeof("OPT")-1);
|
|
|
|
auto qt1_bid_px = qt1.add<BidPx>(25200.0,-1,-1);
|
|
auto qt1_bid_sz = qt1.add<BidSize>(1);
|
|
auto qt1_offer_px = qt1.add<OfferPx>(25200.0,-1,-1);
|
|
auto qt1_offer_sz = qt1.add<OfferSize>(1);
|
|
|
|
FIXFragment qt2;
|
|
auto qt2_quote_entry_id = qt2.add<QuoteEntryID>("10857",sizeof("10857")-1);
|
|
qt2.add<Symbol>("55",sizeof("55")-1);
|
|
qt2.add<SecurityDesc>("ESK5 C1855",sizeof("ESK5 C1855")-1);
|
|
qt2.add<SecurityType>("OPT",sizeof("OPT")-1);
|
|
|
|
auto qt2_bid_px = qt2.add<BidPx>(25200.0,-1,-1);
|
|
auto qt2_bid_sz = qt2.add<BidSize>(1);
|
|
auto qt2_offer_px = qt2.add<OfferPx>(25200.0,-1,-1);
|
|
auto qt2_offer_sz = qt2.add<OfferSize>(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<TotQuoteEntries>(2);
|
|
g.add<NoQuoteEntries> (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<Checksum>(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 );
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|