aboutsummaryrefslogtreecommitdiff
path: root/tests/framework/instruments
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-01-26 16:07:50 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:45:00 +0000
commitc9afce52fe412e6f09917345b198a1f497571e8d (patch)
treec94791d2bad924cda69ff170001005497d2b761f /tests/framework/instruments
parentf6402dd37092c842d1de9998b23640caf12f227b (diff)
downloadComputeLibrary-c9afce52fe412e6f09917345b198a1f497571e8d.tar.gz
COMPMID-863: Remove some of the post-processing from the JSON backend
Refactored the console printer too (So that we can re-use the code if needed) Change-Id: I16a0f70104f82f07cd59900b383038fa5a76e1bc Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/117858 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com>
Diffstat (limited to 'tests/framework/instruments')
-rw-r--r--tests/framework/instruments/Instrument.h3
-rw-r--r--tests/framework/instruments/InstrumentsStats.cpp70
-rw-r--r--tests/framework/instruments/InstrumentsStats.h89
3 files changed, 161 insertions, 1 deletions
diff --git a/tests/framework/instruments/Instrument.h b/tests/framework/instruments/Instrument.h
index 9156d70010..e25939a284 100644
--- a/tests/framework/instruments/Instrument.h
+++ b/tests/framework/instruments/Instrument.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -88,6 +88,7 @@ inline std::unique_ptr<Instrument> Instrument::make_instrument()
{
return support::cpp14::make_unique<T>(scale);
}
+
} // namespace framework
} // namespace test
} // namespace arm_compute
diff --git a/tests/framework/instruments/InstrumentsStats.cpp b/tests/framework/instruments/InstrumentsStats.cpp
new file mode 100644
index 0000000000..2b05e45aad
--- /dev/null
+++ b/tests/framework/instruments/InstrumentsStats.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "InstrumentsStats.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace framework
+{
+InstrumentsStats::InstrumentsStats(const std::vector<Measurement> &measurements)
+ : _min(nullptr), _max(nullptr), _median(nullptr), _mean(measurements.begin()->value().is_floating_point), _stddev(0.0)
+{
+ auto cmp_measurements = [](const Measurement & a, const Measurement & b)
+ {
+ return a.value() < b.value();
+ };
+
+ auto add_measurements = [](Measurement::Value a, const Measurement & b)
+ {
+ return a + b.value();
+ };
+
+ //Calculate min & max
+ const auto values = std::minmax_element(measurements.begin(), measurements.end(), cmp_measurements);
+ _min = &(*values.first);
+ _max = &(*values.second);
+
+ // Calculate the median value
+ auto copy = measurements;
+ std::nth_element(copy.begin(), copy.begin() + (copy.size() / 2), copy.end(), cmp_measurements);
+ _median = &copy[copy.size() / 2];
+
+ Measurement::Value sum_values = std::accumulate(measurements.begin(), measurements.end(), Measurement::Value(_min->value().is_floating_point), add_measurements);
+
+ // Calculate the relative standard deviation
+ _mean = sum_values / measurements.size();
+ std::vector<Measurement::Value> diff(measurements.size(), _min->value().is_floating_point);
+ std::transform(measurements.begin(), measurements.end(), diff.begin(), [&](const Measurement & x)
+ {
+ return x.value() - _mean;
+ });
+ auto sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), Measurement::Value(_min->value().is_floating_point));
+ auto variance = sq_sum / measurements.size();
+ _stddev = Measurement::Value::relative_standard_deviation(variance, _mean);
+}
+} // namespace framework
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/framework/instruments/InstrumentsStats.h b/tests/framework/instruments/InstrumentsStats.h
new file mode 100644
index 0000000000..f1085aafb8
--- /dev/null
+++ b/tests/framework/instruments/InstrumentsStats.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_TEST_INSTRUMENTSMAP
+#define ARM_COMPUTE_TEST_INSTRUMENTSMAP
+
+#include "Measurement.h"
+
+#include <vector>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace framework
+{
+/** Generate common statistics for a set of measurements
+ */
+class InstrumentsStats
+{
+public:
+ /** Compute statistics for the passed set of measurements
+ *
+ * @param[in] measurements The measurements to process
+ */
+ InstrumentsStats(const std::vector<Measurement> &measurements);
+ /** The measurement with the minimum value
+ */
+ const Measurement &min() const
+ {
+ return *_min;
+ }
+ /** The measurement with the maximum value
+ */
+ const Measurement &max() const
+ {
+ return *_max;
+ }
+ /** The median measurement
+ */
+ const Measurement &median() const
+ {
+ return *_median;
+ }
+ /** The average of all the measurements
+ */
+ const Measurement::Value &mean() const
+ {
+ return _mean;
+ }
+ /** The relative standard deviation of the measurements
+ */
+ double relative_standard_deviation() const
+ {
+ return _stddev;
+ }
+
+private:
+ const Measurement *_min;
+ const Measurement *_max;
+ const Measurement *_median;
+ Measurement::Value _mean;
+ double _stddev;
+};
+
+} // namespace framework
+} // namespace test
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_TEST_INSTRUMENTSMAP */