diff options
| author | Eric Dao <eric@erickhangdao.com> | 2025-03-10 17:54:31 -0400 |
|---|---|---|
| committer | Eric Dao <eric@erickhangdao.com> | 2025-03-10 17:54:31 -0400 |
| commit | ab224e2e6ba65f5a369ec392f99cd8845ad06c98 (patch) | |
| tree | a1e757e9341863ed52b8ad4c5a1c45933aab9da4 /python/openvino/runtime/common/utils/src/latency_metrics.cpp | |
| parent | 40da1752f2c8639186b72f6838aa415e854d0b1d (diff) | |
| download | thesis-master.tar.gz thesis-master.tar.bz2 thesis-master.zip | |
Diffstat (limited to 'python/openvino/runtime/common/utils/src/latency_metrics.cpp')
| -rw-r--r-- | python/openvino/runtime/common/utils/src/latency_metrics.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/python/openvino/runtime/common/utils/src/latency_metrics.cpp b/python/openvino/runtime/common/utils/src/latency_metrics.cpp new file mode 100644 index 0000000..c6c3d15 --- /dev/null +++ b/python/openvino/runtime/common/utils/src/latency_metrics.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +// clang-format off +#include <algorithm> +#include <map> +#include <string> +#include <utility> +#include <vector> + +#include "samples/latency_metrics.hpp" +// clang-format on + +void LatencyMetrics::write_to_stream(std::ostream& stream) const { + std::ios::fmtflags fmt(stream.flags()); + stream << data_shape << ";" << std::fixed << std::setprecision(2) << median_or_percentile << ";" << avg << ";" + << min << ";" << max; + stream.flags(fmt); +} + +void LatencyMetrics::write_to_slog() const { + std::string percentileStr = (percentile_boundary == 50) + ? " Median: " + : " " + std::to_string(percentile_boundary) + " percentile: "; + + slog::info << percentileStr << double_to_string(median_or_percentile) << " ms" << slog::endl; + slog::info << " Average: " << double_to_string(avg) << " ms" << slog::endl; + slog::info << " Min: " << double_to_string(min) << " ms" << slog::endl; + slog::info << " Max: " << double_to_string(max) << " ms" << slog::endl; +} + +void LatencyMetrics::fill_data(std::vector<double> latencies, size_t percentile_boundary) { + if (latencies.empty()) { + throw std::logic_error("Latency metrics class expects non-empty vector of latencies at consturction."); + } + std::sort(latencies.begin(), latencies.end()); + min = latencies[0]; + avg = std::accumulate(latencies.begin(), latencies.end(), 0.0) / latencies.size(); + median_or_percentile = latencies[size_t(latencies.size() / 100.0 * percentile_boundary)]; + max = latencies.back(); +}; |
