From 022b61ff9218b427831a182b8df929fde36a20eb Mon Sep 17 00:00:00 2001 From: khyperia Date: Wed, 26 Feb 2020 15:32:34 +0100 Subject: [PATCH] Don't cast nanoseconds to integers when writing output --- include/reporters/catch_reporter_console.cpp | 12 ++++-------- include/reporters/catch_reporter_xml.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/include/reporters/catch_reporter_console.cpp b/include/reporters/catch_reporter_console.cpp index be00d0bdf3..97290c6f8d 100644 --- a/include/reporters/catch_reporter_console.cpp +++ b/include/reporters/catch_reporter_console.cpp @@ -210,15 +210,11 @@ class Duration { static const uint64_t s_nanosecondsInASecond = 1000 * s_nanosecondsInAMillisecond; static const uint64_t s_nanosecondsInAMinute = 60 * s_nanosecondsInASecond; - uint64_t m_inNanoseconds; + double m_inNanoseconds; Unit m_units; public: - explicit Duration(double inNanoseconds, Unit units = Unit::Auto) - : Duration(static_cast(inNanoseconds), units) { - } - - explicit Duration(uint64_t inNanoseconds, Unit units = Unit::Auto) + explicit Duration(double inNanoseconds, Unit units = Unit::Auto) : m_inNanoseconds(inNanoseconds), m_units(units) { if (m_units == Unit::Auto) { @@ -247,7 +243,7 @@ class Duration { case Unit::Minutes: return m_inNanoseconds / static_cast(s_nanosecondsInAMinute); default: - return static_cast(m_inNanoseconds); + return m_inNanoseconds; } } auto unitsAsString() const -> std::string { @@ -698,4 +694,4 @@ CATCH_REGISTER_REPORTER("console", ConsoleReporter) #if defined(__clang__) # pragma clang diagnostic pop -#endif \ No newline at end of file +#endif diff --git a/include/reporters/catch_reporter_xml.cpp b/include/reporters/catch_reporter_xml.cpp index e110317c46..0fb78be03d 100644 --- a/include/reporters/catch_reporter_xml.cpp +++ b/include/reporters/catch_reporter_xml.cpp @@ -229,16 +229,16 @@ namespace Catch { m_xml.writeAttribute("samples", info.samples) .writeAttribute("resamples", info.resamples) .writeAttribute("iterations", info.iterations) - .writeAttribute("clockResolution", static_cast(info.clockResolution)) - .writeAttribute("estimatedDuration", static_cast(info.estimatedDuration)) + .writeAttribute("clockResolution", info.clockResolution) + .writeAttribute("estimatedDuration", info.estimatedDuration) .writeComment("All values in nano seconds"); } void XmlReporter::benchmarkEnded(BenchmarkStats<> const& benchmarkStats) { m_xml.startElement("mean") - .writeAttribute("value", static_cast(benchmarkStats.mean.point.count())) - .writeAttribute("lowerBound", static_cast(benchmarkStats.mean.lower_bound.count())) - .writeAttribute("upperBound", static_cast(benchmarkStats.mean.upper_bound.count())) + .writeAttribute("value", benchmarkStats.mean.point.count()) + .writeAttribute("lowerBound", benchmarkStats.mean.lower_bound.count()) + .writeAttribute("upperBound", benchmarkStats.mean.upper_bound.count()) .writeAttribute("ci", benchmarkStats.mean.confidence_interval); m_xml.endElement(); m_xml.startElement("standardDeviation")