#include "duckhandy/int_conv.hpp" #include #include #include #include #include #include #include namespace { template void run_with_timing ( const std::string& test_name, const std::vector& src, std::vector& dst, Conv&& conv_func ) { dst.clear(); dst.resize(src.size()); std::cout << test_name << "...\n"; const std::size_t count = src.size(); const auto t0 = std::chrono::high_resolution_clock::now(); for (std::size_t z = 0; z < count; ++z) { dst[z] = conv_func(src[z]); } const auto t1 = std::chrono::high_resolution_clock::now(); std::chrono::duration duration = t1 - t0; std::cout << count << " conversions completed in " << duration.count() << " seconds\n"; } } //unnamed namespace int main() { using dhandy::int_conv; constexpr const std::size_t count = 70'000'000; std::vector nums; std::vector strings; std::mt19937 gen; std::cout << "Setting up data...\n"; nums.resize(count); strings.reserve(count); gen.seed(std::time(nullptr)); std::cout << "Generating " << count << " random values...\n"; std::generate(nums.begin(), nums.end(), gen); run_with_timing("Conversions with std::to_string", nums, strings, [](unsigned int n) { return std::to_string(n); }); run_with_timing("AryConversion with dhandy::int_conv", nums, strings, [](unsigned int n) { return int_conv(n); }); std::cout << "All done, bye!\n"; return 0; }