Skip to content

Commit

Permalink
Merge pull request #273 from ckormanyos/time_point_rnd_seed
Browse files Browse the repository at this point in the history
Time point random seed
  • Loading branch information
ckormanyos authored Oct 28, 2023
2 parents df58790 + eb4cdb3 commit bd6f3f8
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wide_decimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wide_decimal_sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: sonar-gcc-native
runs-on: ubuntu-latest
env:
SONAR_SCANNER_VERSION: 4.8.0.2856
SONAR_SCANNER_VERSION: 5.0.1.3006
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
steps:
Expand Down
15 changes: 4 additions & 11 deletions examples/example008_bernoulli_tgamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define WIDE_DECIMAL_DISABLE_USE_STD_FUNCTION

#if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM)
#include <chrono>
#include <ctime>
#endif

#include <examples/example_decwide_t.h>
Expand Down Expand Up @@ -353,24 +353,17 @@ auto ::math::wide_decimal::example008_bernoulli_tgamma() -> bool
#endif
{
#if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM)
using local_clock_type = std::chrono::high_resolution_clock;

const auto start = local_clock_type::now();
const auto begin = std::clock();
#endif

const auto result_is_ok = example008_bernoulli::example008_bernoulli_tgamma_run();

#if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM)
const auto stop = local_clock_type::now();
const auto end = std::clock();
#endif

#if !defined(WIDE_DECIMAL_DISABLE_IOSTREAM)
const auto elapsed =
static_cast<float>
(
static_cast<float>(std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count())
/ static_cast<float>(1000.0F)
);
const auto elapsed = static_cast<float>(static_cast<float>(end - begin) / CLOCKS_PER_SEC);

std::cout << "Time example008_bernoulli_tgamma() : "
<< elapsed
Expand Down
37 changes: 11 additions & 26 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
// cov-build --dir cov-int g++ -fno-rtti -fno-exceptions -finline-functions -finline-limit=64 -march=native -mtune=native -O3 -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wshadow -Wunused-parameter -Wuninitialized -Wunreachable-code -Winit-self -Wzero-as-null-pointer-constant -std=c++14 -DWIDE_DECIMAL_NAMESPACE=ckormanyos -I. -I/mnt/c/boost/boost_1_82_0 -pthread -lpthread test/test.cpp test/test_decwide_t_algebra.cpp test/test_decwide_t_algebra_edge.cpp test/test_decwide_t_examples.cpp examples/example000a_multiply_pi_squared.cpp examples/example000_multiply_nines.cpp examples/example001_roots_sqrt.cpp examples/example001a_roots_seventh.cpp examples/example001b_roots_almost_integer.cpp examples/example001c_roots_sqrt_limb08.cpp examples/example001d_pow2_from_list.cpp examples/example002_pi.cpp examples/example002a_pi_small_limb.cpp examples/example002b_pi_100k.cpp examples/example002c_pi_quintic.cpp examples/example002d_pi_limb08.cpp examples/example003_zeta.cpp examples/example004_bessel_recur.cpp examples/example005_polylog_series.cpp examples/example006_logarithm.cpp examples/example007_catalan_series.cpp examples/example008_bernoulli_tgamma.cpp examples/example009_boost_math_standalone.cpp examples/example009a_boost_math_standalone.cpp examples/example009b_boost_math_standalone.cpp examples/example010_hypergeometric_2f1.cpp examples/example010a_hypergeometric_1f1.cpp examples/example011_trig_trapezoid_integral.cpp examples/example012_rational_floor_ceil.cpp examples/example013_embeddable_sqrt.cpp examples/example013a_embeddable_agm.cpp -o wide_decimal.exe
// tar caf wide-decimal.bz2 cov-int

#include <chrono>
#include <cstdint>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
Expand All @@ -43,21 +44,13 @@ namespace local
template<typename RunnerFunctionType>
auto pfn_runner(const RunnerFunctionType& pfn_test, const char* p_msg) -> bool
{
using local_clock_type = std::chrono::high_resolution_clock;

const auto start = local_clock_type::now();
const auto begin = std::clock();

const auto result_test_is_ok = pfn_test();

const auto elapsed =
static_cast<float>
(
static_cast<float>
(
std::chrono::duration_cast<std::chrono::milliseconds>(local_clock_type::now() - start).count()
)
/ static_cast<float>(UINT16_C(1000))
);
const auto end = std::clock();

const auto elapsed = static_cast<float>(static_cast<float>(end - begin) / CLOCKS_PER_SEC);

const auto flg = std::cout.flags();

Expand Down Expand Up @@ -113,29 +106,21 @@ auto local::run() -> bool

auto main() -> int
{
using local_clock_type = std::chrono::high_resolution_clock;

const auto start = local_clock_type::now();
const auto begin = std::clock();

const auto result_is_ok = local::run();

const auto test_duration_sec =
static_cast<float>
(
static_cast<float>
(
std::chrono::duration_cast<std::chrono::milliseconds>(local_clock_type::now() - start).count()
)
/ static_cast<float>(UINT16_C(1000))
);
const auto end = std::clock();

const auto elapsed = static_cast<float>(static_cast<float>(end - begin) / CLOCKS_PER_SEC);

const auto flg = std::cout.flags();

std::cout << "result_is_ok : "
<< std::boolalpha
<< result_is_ok
<< ", time: "
<< test_duration_sec
<< elapsed
<< "s"
<< std::endl
;
Expand Down
40 changes: 11 additions & 29 deletions test/test_decwide_t_algebra_edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
#endif

#include <algorithm>
#include <chrono>
#include <cstdint>
#include <ctime>
#include <random>
#include <sstream>
#include <string>

#include <math/wide_decimal/decwide_t.h>
#include <test/test_decwide_t_algebra.h>
#include <util/utility/util_baselexical_cast.h>
#include <util/utility/util_pseudorandom_time_point_seed.h>

#if defined(__clang__)
#if defined __has_feature && (__has_feature(thread_sanitizer) || __has_feature(address_sanitizer))
Expand Down Expand Up @@ -61,25 +62,6 @@ auto local_one () -> const local_wide_decimal_type&;
auto local_near_one() -> const local_wide_decimal_type&;
auto local_not_one () -> const local_wide_decimal_type&;

template<typename IntegralTimePointType,
typename ClockType = std::chrono::high_resolution_clock>
auto time_point() -> IntegralTimePointType
{
using local_integral_time_point_type = IntegralTimePointType;
using local_clock_type = ClockType;

const auto current_now =
static_cast<std::uintmax_t>
(
std::chrono::duration_cast<std::chrono::nanoseconds>
(
local_clock_type::now().time_since_epoch()
).count()
);

return static_cast<local_integral_time_point_type>(current_now);
}

template<typename FloatingPointTypeWithStringConstruction>
auto generate_wide_decimal_value(bool is_positive = false,
int exp_range = 10000, // NOLINT(bugprone-easily-swappable-parameters)
Expand Down Expand Up @@ -229,9 +211,9 @@ auto test_div_by_other_sign_same() -> bool
{
auto result_is_ok = true;

eng_sgn.seed(time_point<typename eng_sgn_type::result_type>());
eng_dig.seed(time_point<typename eng_dig_type::result_type>());
eng_exp.seed(time_point<typename eng_exp_type::result_type>());
eng_sgn.seed(util::util_pseudorandom_time_point_seed::value<typename eng_sgn_type::result_type>());
eng_dig.seed(util::util_pseudorandom_time_point_seed::value<typename eng_dig_type::result_type>());
eng_exp.seed(util::util_pseudorandom_time_point_seed::value<typename eng_exp_type::result_type>());

for(auto i = static_cast<unsigned>(UINT32_C(0));
i < static_cast<unsigned>(UINT32_C(1024));
Expand Down Expand Up @@ -715,9 +697,9 @@ auto test_various_min_max_operations() -> bool
#if !defined(DECWIDE_T_REDUCE_TEST_DEPTH)
auto test_frexp_in_all_ranges() -> bool
{
eng_sgn.seed(time_point<typename eng_sgn_type::result_type>());
eng_dig.seed(time_point<typename eng_dig_type::result_type>());
eng_exp.seed(time_point<typename eng_exp_type::result_type>());
eng_sgn.seed(util::util_pseudorandom_time_point_seed::value<typename eng_sgn_type::result_type>());
eng_dig.seed(util::util_pseudorandom_time_point_seed::value<typename eng_dig_type::result_type>());
eng_exp.seed(util::util_pseudorandom_time_point_seed::value<typename eng_exp_type::result_type>());

auto result_is_ok = true;

Expand Down Expand Up @@ -856,9 +838,9 @@ auto test_frexp_in_all_ranges() -> bool

auto test_string_ops_and_round_trips() -> bool
{
eng_sgn.seed(time_point<typename eng_sgn_type::result_type>());
eng_dig.seed(time_point<typename eng_dig_type::result_type>());
eng_exp.seed(time_point<typename eng_exp_type::result_type>());
eng_sgn.seed(util::util_pseudorandom_time_point_seed::value<typename eng_sgn_type::result_type>());
eng_dig.seed(util::util_pseudorandom_time_point_seed::value<typename eng_dig_type::result_type>());
eng_exp.seed(util::util_pseudorandom_time_point_seed::value<typename eng_exp_type::result_type>());

auto result_is_ok = true;

Expand Down
23 changes: 12 additions & 11 deletions test/test_high_precision_exp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#include <chrono>
///////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2022 - 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 <cmath>
#include <cstdint>
#include <ctime>
Expand Down Expand Up @@ -252,22 +258,17 @@ namespace test_high_precision_exp

int main()
{
const auto start = std::chrono::high_resolution_clock::now();
const auto begin = std::clock();

const bool result_is_ok = test_high_precision_exp::do_test();

const auto stop = std::chrono::high_resolution_clock::now();
const auto end = std::clock();

std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
const auto elapsed = static_cast<float>(static_cast<float>(end - begin) / CLOCKS_PER_SEC);

const auto duration =
static_cast<float>
(
static_cast<float>(std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count())
/ 1000.0F
);
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;

std::cout << "High-precision calculations took: " << std::fixed << std::setprecision(1) << duration << "s" << std::endl;
std::cout << "High-precision calculations took: " << std::fixed << std::setprecision(1) << elapsed << "s" << std::endl;

return (result_is_ok ? 0 : -1);
}
22 changes: 8 additions & 14 deletions test/test_high_precision_log.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
///////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2022. //
// Copyright Christopher Kormanyos 2022- 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 <array>
#include <atomic>
#include <chrono>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -134,23 +134,17 @@ auto main() -> int
using local_hp_float_left_type = test_high_precision_log::local_wide_decimal_high_precision_number_type;
using local_hp_float_right_type = test_high_precision_log::local_boost_high_precision_number_type;

const auto start = std::chrono::high_resolution_clock::now();
const auto begin = std::clock();

const auto result_is_ok =
local::do_calcs_log<local_hp_float_left_type, local_hp_float_right_type>();
const auto result_is_ok = local::do_calcs_log<local_hp_float_left_type, local_hp_float_right_type>();

const auto stop = std::chrono::high_resolution_clock::now();
const auto end = std::clock();

std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;
const auto elapsed = static_cast<float>(static_cast<float>(end - begin) / CLOCKS_PER_SEC);

const auto duration =
static_cast<float>
(
static_cast<float>(std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count())
/ 1000.0F
);
std::cout << "result_is_ok: " << std::boolalpha << result_is_ok << std::endl;

std::cout << "High-precision calculations took: " << std::fixed << std::setprecision(1) << duration << "s" << std::endl;
std::cout << "High-precision calculations took: " << std::fixed << std::setprecision(1) << elapsed << "s" << std::endl;

return (result_is_ok ? 0 : -1);
}
2 changes: 1 addition & 1 deletion util/utility/util_dynamic_array.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2012 - 2023.
// Copyright Christopher Kormanyos 2012 - 2022.
// 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)
Expand Down
Loading

0 comments on commit bd6f3f8

Please sign in to comment.