| 55 | }; |
| 56 | |
| 57 | int main(int argc, char** argv) |
| 58 | { |
| 59 | auto parser = optparse::OptionParser().version("1.0.0.0"); |
| 60 | |
| 61 | parser.add_option("-i", "--input").dest("input").help("Input file name"); |
| 62 | |
| 63 | optparse::Values options = parser.parse_args(argc, argv); |
| 64 | |
| 65 | // Print help |
| 66 | if (options.get("help")) |
| 67 | { |
| 68 | parser.print_help(); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | MyITCHHandler itch_handler; |
| 73 | |
| 74 | // Open the input file or stdin |
| 75 | std::unique_ptr<Reader> input(new StdInput()); |
| 76 | if (options.is_set("input")) |
| 77 | { |
| 78 | File* file = new File(Path(options.get("input"))); |
| 79 | file->Open(true, false); |
| 80 | input.reset(file); |
| 81 | } |
| 82 | |
| 83 | // Perform input |
| 84 | size_t size; |
| 85 | uint8_t buffer[8192]; |
| 86 | std::cout << "ITCH processing..."; |
| 87 | uint64_t timestamp_start = Timestamp::nano(); |
| 88 | while ((size = input->Read(buffer, sizeof(buffer))) > 0) |
| 89 | { |
| 90 | // Process the buffer |
| 91 | itch_handler.Process(buffer, size); |
| 92 | } |
| 93 | uint64_t timestamp_stop = Timestamp::nano(); |
| 94 | std::cout << "Done!" << std::endl; |
| 95 | |
| 96 | std::cout << std::endl; |
| 97 | |
| 98 | std::cout << "Errors: " << itch_handler.errors() << std::endl; |
| 99 | |
| 100 | std::cout << std::endl; |
| 101 | |
| 102 | size_t total_messages = itch_handler.messages(); |
| 103 | |
| 104 | std::cout << "Processing time: " << CppBenchmark::ReporterConsole::GenerateTimePeriod(timestamp_stop - timestamp_start) << std::endl; |
| 105 | std::cout << "Total ITCH messages: " << total_messages << std::endl; |
| 106 | std::cout << "ITCH message latency: " << CppBenchmark::ReporterConsole::GenerateTimePeriod((timestamp_stop - timestamp_start) / total_messages) << std::endl; |
| 107 | std::cout << "ITCH message throughput: " << total_messages * 1000000000 / (timestamp_stop - timestamp_start) << " msg/s" << std::endl; |
| 108 | |
| 109 | return 0; |
| 110 | } |