| 7716 | } |
| 7717 | |
| 7718 | bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) { |
| 7719 | CATCH_INTERNAL_START_WARNINGS_SUPPRESSION |
| 7720 | CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS |
| 7721 | static std::random_device entropy; |
| 7722 | CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION |
| 7723 | |
| 7724 | auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++ |
| 7725 | |
| 7726 | auto mean = &Detail::mean<std::vector<double>::iterator>; |
| 7727 | auto stddev = &standard_deviation; |
| 7728 | |
| 7729 | #if defined(CATCH_CONFIG_USE_ASYNC) |
| 7730 | auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) { |
| 7731 | auto seed = entropy(); |
| 7732 | return std::async(std::launch::async, [=] { |
| 7733 | std::mt19937 rng(seed); |
| 7734 | auto resampled = resample(rng, n_resamples, first, last, f); |
| 7735 | return bootstrap(confidence_level, first, last, resampled, f); |
| 7736 | }); |
| 7737 | }; |
| 7738 | |
| 7739 | auto mean_future = Estimate(mean); |
| 7740 | auto stddev_future = Estimate(stddev); |
| 7741 | |
| 7742 | auto mean_estimate = mean_future.get(); |
| 7743 | auto stddev_estimate = stddev_future.get(); |
| 7744 | #else |
| 7745 | auto Estimate = [=](double(*f)(std::vector<double>::iterator, std::vector<double>::iterator)) { |
| 7746 | auto seed = entropy(); |
| 7747 | std::mt19937 rng(seed); |
| 7748 | auto resampled = resample(rng, n_resamples, first, last, f); |
| 7749 | return bootstrap(confidence_level, first, last, resampled, f); |
| 7750 | }; |
| 7751 | |
| 7752 | auto mean_estimate = Estimate(mean); |
| 7753 | auto stddev_estimate = Estimate(stddev); |
| 7754 | #endif // CATCH_USE_ASYNC |
| 7755 | |
| 7756 | double outlier_variance = Detail::outlier_variance(mean_estimate, stddev_estimate, n); |
| 7757 | |
| 7758 | return { mean_estimate, stddev_estimate, outlier_variance }; |
| 7759 | } |
| 7760 | } // namespace Detail |
| 7761 | } // namespace Benchmark |
| 7762 | } // namespace Catch |