From 7906ffba294fc2637247f8db6369579ce457ad6d Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Thu, 26 Oct 2023 07:15:17 +0200 Subject: [PATCH 1/4] Workaround maybe forever switch chrono/ctime --- examples/example008_miller_rabin_prime.cpp | 19 ++++--------------- examples/example009_timed_mul.cpp | 14 +++++++------- examples/example009a_timed_mul_4_by_4.cpp | 14 +++++++------- examples/example009b_timed_mul_8_by_8.cpp | 14 +++++++------- test/test.cpp | 12 ++++-------- test/test_uintwide_t_edge_cases.cpp | 22 +++++----------------- 6 files changed, 34 insertions(+), 61 deletions(-) diff --git a/examples/example008_miller_rabin_prime.cpp b/examples/example008_miller_rabin_prime.cpp index 42dce43..022136f 100644 --- a/examples/example008_miller_rabin_prime.cpp +++ b/examples/example008_miller_rabin_prime.cpp @@ -10,7 +10,7 @@ // The Boost.Multiprecision code can be found here: // https://www.boost.org/doc/libs/1_73_0/libs/multiprecision/doc/html/boost_multiprecision/tut/primetest.html -#include +#include #include #include @@ -43,23 +43,12 @@ namespace local_example008_miller_rabin_prime using random_engine1_type = std::linear_congruential_engine; using random_engine2_type = std::mt19937; - template + template auto time_point() -> IntegralTimePointType { using local_integral_time_point_type = IntegralTimePointType; - using local_clock_type = ClockType; - - const auto current_now = - static_cast - ( - std::chrono::duration_cast - ( - local_clock_type::now().time_since_epoch() - ).count() - ); - - return static_cast(current_now); + + return static_cast(std::clock()); } auto example008_miller_rabin_prime_run() -> bool diff --git a/examples/example009_timed_mul.cpp b/examples/example009_timed_mul.cpp index 6edce8f..d59cec8 100644 --- a/examples/example009_timed_mul.cpp +++ b/examples/example009_timed_mul.cpp @@ -6,9 +6,9 @@ /////////////////////////////////////////////////////////////////// #include -#include #include #include +#include #include #include #include @@ -89,17 +89,17 @@ auto ::math::wide_integer::example009_timed_mul() -> bool std::uint64_t count = 0U; std::size_t index = 0U; - std::intmax_t total_time { }; + float total_time { }; - const std::chrono::high_resolution_clock::time_point begin = std::chrono::high_resolution_clock::now(); + const auto begin = std::clock(); for(;;) { local_timed_mul::local_a().at(index) * local_timed_mul::local_b().at(index); - const std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); + const auto end = std::clock(); - total_time = static_cast(std::chrono::duration_cast(end - begin).count()); + total_time = static_cast(static_cast(end - begin) / CLOCKS_PER_SEC); ++count; ++index; @@ -109,13 +109,13 @@ auto ::math::wide_integer::example009_timed_mul() -> bool index = 0U; } - if(total_time > INTMAX_C(5999)) + if(total_time > static_cast(6.0L)) { break; } } - const float kops_per_sec = static_cast(count) / static_cast(static_cast(total_time)); + const float kops_per_sec = static_cast(count) / static_cast(static_cast(total_time * 1000.0F)); { const auto flg = std::cout.flags(); diff --git a/examples/example009a_timed_mul_4_by_4.cpp b/examples/example009a_timed_mul_4_by_4.cpp index 131ce4f..631a68a 100644 --- a/examples/example009a_timed_mul_4_by_4.cpp +++ b/examples/example009a_timed_mul_4_by_4.cpp @@ -6,9 +6,9 @@ /////////////////////////////////////////////////////////////////// #include -#include #include #include +#include #include #include #include @@ -87,9 +87,9 @@ auto ::math::wide_integer::example009a_timed_mul_4_by_4() -> bool std::uint64_t count = 0U; std::size_t index = 0U; - std::intmax_t total_time { }; + float total_time { }; - const std::chrono::high_resolution_clock::time_point begin = std::chrono::high_resolution_clock::now(); + const auto begin = std::clock(); for(;;) { @@ -98,9 +98,9 @@ auto ::math::wide_integer::example009a_timed_mul_4_by_4() -> bool local_timed_mul_4_by_4::local_a().at(index + 2U) * local_timed_mul_4_by_4::local_b().at(index + 2U); local_timed_mul_4_by_4::local_a().at(index + 3U) * local_timed_mul_4_by_4::local_b().at(index + 3U); - const std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); + const auto end = std::clock(); - total_time = static_cast(std::chrono::duration_cast(end - begin).count()); + total_time = static_cast(static_cast(end - begin) / CLOCKS_PER_SEC); count += 4U; index += 4U; @@ -110,13 +110,13 @@ auto ::math::wide_integer::example009a_timed_mul_4_by_4() -> bool index = 0U; } - if(total_time > INTMAX_C(5999)) + if(total_time > static_cast(6.0L)) { break; } } - const float kops_per_sec = static_cast(count) / static_cast(static_cast(total_time)); + const float kops_per_sec = static_cast(count) / static_cast(static_cast(total_time * 1000.0F)); { const auto flg = std::cout.flags(); diff --git a/examples/example009b_timed_mul_8_by_8.cpp b/examples/example009b_timed_mul_8_by_8.cpp index 3a19739..a1cc543 100644 --- a/examples/example009b_timed_mul_8_by_8.cpp +++ b/examples/example009b_timed_mul_8_by_8.cpp @@ -6,9 +6,9 @@ /////////////////////////////////////////////////////////////////// #include -#include #include #include +#include #include #include #include @@ -87,9 +87,9 @@ auto ::math::wide_integer::example009b_timed_mul_8_by_8() -> bool std::uint64_t count = 0U; std::size_t index = 0U; - std::intmax_t total_time { }; + float total_time { }; - const std::chrono::high_resolution_clock::time_point begin = std::chrono::high_resolution_clock::now(); + const auto begin = std::clock(); for(;;) { @@ -98,9 +98,9 @@ auto ::math::wide_integer::example009b_timed_mul_8_by_8() -> bool local_timed_mul_8_by_8::local_a().at(index + 2U) * local_timed_mul_8_by_8::local_b().at(index + 2U); local_timed_mul_8_by_8::local_a().at(index + 3U) * local_timed_mul_8_by_8::local_b().at(index + 3U); - const std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now(); + const auto end = std::clock(); - total_time = static_cast(std::chrono::duration_cast(end - begin).count()); + total_time = static_cast(static_cast(end - begin) / CLOCKS_PER_SEC); count += 4U; index += 4U; @@ -110,13 +110,13 @@ auto ::math::wide_integer::example009b_timed_mul_8_by_8() -> bool index = 0U; } - if(total_time > INTMAX_C(5999)) + if(total_time > static_cast(6.0L)) { break; } } - const float kops_per_sec = static_cast(count) / static_cast(static_cast(total_time)); + const float kops_per_sec = static_cast(count) / static_cast(static_cast(total_time * 1000.0F)); { const auto flg = std::cout.flags(); diff --git a/test/test.cpp b/test/test.cpp index 60f5757..d9d4d0c 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -30,7 +30,7 @@ // cov-build --dir cov-int g++ -finline-functions -march=native -mtune=native -O3 -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -std=c++14 -DWIDE_INTEGER_HAS_LIMB_TYPE_UINT64 -DWIDE_INTEGER_HAS_MUL_8_BY_8_UNROLL -I. -I/mnt/c/boost/boost_1_83_0 -pthread -lpthread test/test.cpp test/test_uintwide_t_boost_backend.cpp test/test_uintwide_t_edge_cases.cpp test/test_uintwide_t_examples.cpp test/test_uintwide_t_float_convert.cpp test/test_uintwide_t_int_convert.cpp test/test_uintwide_t_n_base.cpp test/test_uintwide_t_n_binary_ops_base.cpp examples/example000a_builtin_convert.cpp test/test_uintwide_t_spot_values.cpp examples/example000_numeric_limits.cpp examples/example001_mul_div.cpp examples/example001a_div_mod.cpp examples/example002_shl_shr.cpp examples/example003_sqrt.cpp examples/example003a_cbrt.cpp examples/example004_rootk_pow.cpp examples/example005_powm.cpp examples/example005a_pow_factors_of_p99.cpp examples/example006_gcd.cpp examples/example007_random_generator.cpp examples/example008_miller_rabin_prime.cpp examples/example008a_miller_rabin_prime.cpp examples/example009_timed_mul.cpp examples/example009a_timed_mul_4_by_4.cpp examples/example009b_timed_mul_8_by_8.cpp examples/example010_uint48_t.cpp examples/example011_uint24_t.cpp examples/example012_rsa_crypto.cpp examples/example013_ecdsa_sign_verify.cpp examples/example014_pi_spigot_wide.cpp -o wide_integer.exe // tar caf wide-integer.bz2 cov-int -#include +#include #include #include @@ -99,10 +99,6 @@ namespace local { -using clock_type = std::chrono::high_resolution_clock; - -const auto wide_decimal_time_start = clock_type::now(); - #if !defined(UINTWIDE_T_REDUCE_TEST_DEPTH) constexpr auto test_uintwide_t_n_binary_ops_rounds = static_cast(4U); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) #else @@ -549,7 +545,7 @@ auto run() -> bool // NOLINT(readability-function-cognitive-complexity) using boost_wrapexcept_runtime_type = ::boost::wrapexcept; #endif - const auto start = clock_type::now(); + const auto start = std::clock(); bool result_is_ok = true; @@ -607,7 +603,7 @@ auto run() -> bool // NOLINT(readability-function-cognitive-complexity) } #endif - const auto stop = clock_type::now(); + const auto stop = std::clock(); { constexpr auto one_thousand_milliseconds = 1000.0F; @@ -620,7 +616,7 @@ auto run() -> bool // NOLINT(readability-function-cognitive-complexity) << ", time: " << std::fixed << std::setprecision(1) - << (static_cast(std::chrono::duration_cast(stop - start).count())) / one_thousand_milliseconds + << static_cast(static_cast(stop - start) / CLOCKS_PER_SEC) << "s" << std::endl; diff --git a/test/test_uintwide_t_edge_cases.cpp b/test/test_uintwide_t_edge_cases.cpp index a722b5e..131cf90 100644 --- a/test/test_uintwide_t_edge_cases.cpp +++ b/test/test_uintwide_t_edge_cases.cpp @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2022. +// Copyright Christopher Kormanyos 2019 - 2023. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include +#include #include #include #include @@ -103,8 +103,7 @@ constexpr auto loop_count_hi = static_cast(UINT16_C(8)); #endif // Forward declaration -template +template auto time_point() -> IntegralTimePointType; #if defined(WIDE_INTEGER_NAMESPACE) @@ -170,23 +169,12 @@ auto zero_as_small_unsigned_type() -> const local_uintwide_t_small_unsigned_type auto one_as_small_unsigned_type () -> const local_uintwide_t_small_unsigned_type&; auto m_one_as_small_signed_type () -> const local_uintwide_t_small_signed_type&; -template +template auto time_point() -> IntegralTimePointType { using local_integral_time_point_type = IntegralTimePointType; - using local_clock_type = ClockType; - const auto current_now = - static_cast - ( - std::chrono::duration_cast - ( - local_clock_type::now().time_since_epoch() - ).count() - ); - - return static_cast(current_now); + return static_cast(std::clock()); } template From 84a7a2cc45eb480de93bcca76c5616f0d2b5826e Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Thu, 26 Oct 2023 07:41:25 +0200 Subject: [PATCH 2/4] Remove an unused variable --- test/test.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test.cpp b/test/test.cpp index d9d4d0c..7615042 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -606,8 +606,6 @@ auto run() -> bool // NOLINT(readability-function-cognitive-complexity) const auto stop = std::clock(); { - constexpr auto one_thousand_milliseconds = 1000.0F; - const auto flg = std::cout.flags(); std::cout << "result_is_ok: " From c31dd2ffbfbb1096e0a2f0ad091f68e81f3b6a1a Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Thu, 26 Oct 2023 08:08:14 +0200 Subject: [PATCH 3/4] Handle some clang-tidy messages --- examples/example009_timed_mul.cpp | 2 +- examples/example009a_timed_mul_4_by_4.cpp | 2 +- examples/example009b_timed_mul_8_by_8.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/example009_timed_mul.cpp b/examples/example009_timed_mul.cpp index d59cec8..a50d612 100644 --- a/examples/example009_timed_mul.cpp +++ b/examples/example009_timed_mul.cpp @@ -109,7 +109,7 @@ auto ::math::wide_integer::example009_timed_mul() -> bool index = 0U; } - if(total_time > static_cast(6.0L)) + if(total_time > static_cast(6.0L)) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) { break; } diff --git a/examples/example009a_timed_mul_4_by_4.cpp b/examples/example009a_timed_mul_4_by_4.cpp index 631a68a..26e9d32 100644 --- a/examples/example009a_timed_mul_4_by_4.cpp +++ b/examples/example009a_timed_mul_4_by_4.cpp @@ -110,7 +110,7 @@ auto ::math::wide_integer::example009a_timed_mul_4_by_4() -> bool index = 0U; } - if(total_time > static_cast(6.0L)) + if(total_time > static_cast(6.0L)) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) { break; } diff --git a/examples/example009b_timed_mul_8_by_8.cpp b/examples/example009b_timed_mul_8_by_8.cpp index a1cc543..ac214e5 100644 --- a/examples/example009b_timed_mul_8_by_8.cpp +++ b/examples/example009b_timed_mul_8_by_8.cpp @@ -110,7 +110,7 @@ auto ::math::wide_integer::example009b_timed_mul_8_by_8() -> bool index = 0U; } - if(total_time > static_cast(6.0L)) + if(total_time > static_cast(6.0L)) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) { break; } From ea86a00470c4cbd8381c7d73d91a88b5e0e5c9e5 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Fri, 27 Oct 2023 06:27:29 +0200 Subject: [PATCH 4/4] Remove c++ std 2b from clang 14 in CI --- .github/workflows/wide_integer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wide_integer.yml b/.github/workflows/wide_integer.yml index 165baaf..9f6dce0 100644 --- a/.github/workflows/wide_integer.yml +++ b/.github/workflows/wide_integer.yml @@ -257,7 +257,7 @@ jobs: strategy: fail-fast: false matrix: - standard: [ c++14, c++17, c++20, c++2b ] + standard: [ c++14, c++17, c++20 ] compiler: [ g++-12, clang++-14 ] steps: - uses: actions/checkout@v3 @@ -818,7 +818,7 @@ jobs: strategy: fail-fast: false matrix: - standard: [ c++20, c++2b ] + standard: [ c++20 ] compiler: [ g++-12, clang++-14 ] suite: [ test_uintwide_t_xtra_from_issue_335 ] steps: