catch_sample_analysis.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Created by Joachim on 16/04/2019.
  3. * Adapted from donated nonius code.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. // Benchmark results
  9. #ifndef TWOBLUECUBES_CATCH_BENCHMARK_RESULTS_HPP_INCLUDED
  10. #define TWOBLUECUBES_CATCH_BENCHMARK_RESULTS_HPP_INCLUDED
  11. #include "catch_clock.hpp"
  12. #include "catch_estimate.hpp"
  13. #include "catch_outlier_classification.hpp"
  14. #include <algorithm>
  15. #include <vector>
  16. #include <string>
  17. #include <iterator>
  18. namespace Catch {
  19. namespace Benchmark {
  20. template <typename Duration>
  21. struct SampleAnalysis {
  22. std::vector<Duration> samples;
  23. Estimate<Duration> mean;
  24. Estimate<Duration> standard_deviation;
  25. OutlierClassification outliers;
  26. double outlier_variance;
  27. template <typename Duration2>
  28. operator SampleAnalysis<Duration2>() const {
  29. std::vector<Duration2> samples2;
  30. samples2.reserve(samples.size());
  31. std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
  32. return {
  33. std::move(samples2),
  34. mean,
  35. standard_deviation,
  36. outliers,
  37. outlier_variance,
  38. };
  39. }
  40. };
  41. } // namespace Benchmark
  42. } // namespace Catch
  43. #endif // TWOBLUECUBES_CATCH_BENCHMARK_RESULTS_HPP_INCLUDED