OnixS C++ FIX Engine  4.10.1
API Documentation
Parser Sample

This sample shows how to measure the parsing performance.

Source code:

#include <cmath>
#include "../../Common/PrecisionTimer.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
int main(int argc, char * argv[])
{
std::string fileName = (2 == argc) ? argv[1] : "Order.fix";
try {
EngineSettings settings;
settings.listenPort(-1) // '-1' disables the telecommunication level.
.licenseStore(LicenseStore)
.dictionaryFile("ParserFixDictionary.xml");
Engine::init(settings);
Dictionary dictionary("ParserDictionaryId");
std::ifstream in(fileName.c_str());
if(!in)
throw std::domain_error(std::string("Cannot open file ") + fileName);
std::string raw;
std::getline(in, raw);
std::clog
<< "Raw FIX message:\n"
<< raw
<< std::endl;
const size_t N_CYCLES = 10000;
size_t iteration = N_CYCLES;
PrecisionTimer timer;
const Message Blank;
Message parsed;
while(iteration--) {
Message::parse(
raw.data(), raw.size(),
dictionary,
MessageParsingFlag::None,
parsed);
// Quick way to reset message to unconstructed state.
// Once message is valid, reset will just wipe out fields,
// message will remain valid and will hold internal structures.
parsed = Blank;
}
timer.stop();
double performance = 0;
if(0 != timer.elapsed())
performance = floor((double) N_CYCLES * 1000 / timer.elapsed());
std::clog << "\nParsing Performance: " << performance << " msg/sec." << std::endl << std::endl;
std::clog << "Press any key to terminate the application." << std::endl;
#ifdef _WIN32
_getch();
#endif
#ifdef __linux__
getchar();
#endif
Engine::shutdown();
}
catch(const std::exception & ex) {
processSampleException(ex.what());
}
return 0;
}