#include "parselink/msgpack/token.h" #include #include #include #include #include using namespace std::chrono_literals; auto read_file(char const* filename) { std::vector data; auto fd = open(filename, O_RDONLY); if (!fd) { fmt::print("Could not open {}: {}\n", filename, strerror(errno)); return data; } auto size = lseek(fd, 0, SEEK_END); data.resize(size); lseek(fd, 0, SEEK_SET); fmt::print("Reading {} bytes from {}\n", size, filename); read(fd, data.data(), data.size()); close(fd); return data; } int main(int argc, char** argv) { std::array buf; auto data = read_file(argc < 2 ? "output.bin" : argv[1]); msgpack::token_reader reader(data); auto before = std::chrono::steady_clock::now(); auto test = reader.read_some(buf); auto after = std::chrono::steady_clock::now(); test.map([&](auto sp){ fmt::print("Read {} tokens\n", sp.size()); }).map_error([&](auto err){ fmt::print("Failed to read tokens: {}\n", (int)err); }); fmt::print("Took {} us\n", (after - before) / 1us); }