OnixS C++ FIX Engine  4.10.1
API Documentation
Fast Benchmark Sample

This sample demonstrates how to measure performance of FAST encoding/decoding.

Source code:

#include "CountingListener.h"
#include "../../Common/PrecisionTimer.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
namespace {
void decode();
void decodeEventBased();
};
int main(int argc, const char * argv[])
{
#ifndef NDEBUG
std::cerr << "Please use RELEASE build to measure performance." << std::endl;
return 1;
#endif
try {
EngineSettings engineSettings;
engineSettings.dictionaryFile("CmeFastFixDialect.xml")
.listenPort(-1) // ListenPort is set to '-1' to disable the telecommunication level.
.licenseStore(LicenseStore);
Engine::init(engineSettings);
if(argc > 1 && !strcmp(argv[1], "-c"))
decodeEventBased();
else
decode();
waitUntilEnterKey();
}
catch(const std::exception & ex) {
processSampleException(ex.what());
return 3;
}
}
namespace {
void decode()
{
const std::string fastTemplates = readTextFile("CmeFastTemplate.xml");
Decoder decoder(fastTemplates, fixVersion, true,
InputDataTraits::CompleteMessagesOnly);
std::string binaryChunk = readBinaryFile("cmeBinaryFastMessage.bin");
PrecisionTimer timer;
const int numberOfMessages = 1000000;
for(int i = 0; i < numberOfMessages; ++i)
decoder.decode(binaryChunk.data(), binaryChunk.size());
timer.stop();
long performance = timer.itemsPerSecond(numberOfMessages);
std::clog << std::endl << "\tFAST Decoding: " << performance << " msg/sec " << std::endl << std::endl;
const Message & decodedMessage = decoder.decode(binaryChunk.data(), binaryChunk.size());
std::clog << "Decoded message: " << decodedMessage << std::endl;
}
void decodeEventBased()
{
std::string fastTemplates = readTextFile("CmeFastTemplate.xml");
EventBasedDecoder decoder(fastTemplates, fixVersion, true, InputDataTraits::CompleteMessagesOnly);
std::string binaryChunk = readBinaryFile("cmeBinaryFastMessage.bin");
PrecisionTimer timer;
CountingListener listener;
size_t usedSize = 0;
const int numberOfMessages = 10000000;
for(int i = 0; i < numberOfMessages; ++i)
decoder.decode(binaryChunk.data(), binaryChunk.size(), &listener, &usedSize);
timer.stop();
long performance = timer.itemsPerSecond(numberOfMessages);
std::clog << std::endl << "\tFAST event-based decoding: " << performance << " msg/sec " << std::endl << std::endl;
std::clog << "Messages: " << listener.messageCount() << std::endl;
std::clog << "Fields: " << listener.fieldCount() << std::endl;
}
};