| 41 | //! |
| 42 | template <typename T> |
| 43 | float findPercentile(float percentile, std::vector<InferenceTime> const& timings, T const& toFloat) |
| 44 | { |
| 45 | int32_t const all = static_cast<int32_t>(timings.size()); |
| 46 | int32_t const exclude = static_cast<int32_t>((1 - percentile / 100) * all); |
| 47 | if (timings.empty()) |
| 48 | { |
| 49 | return std::numeric_limits<float>::infinity(); |
| 50 | } |
| 51 | if (percentile < 0.F || percentile > 100.F) |
| 52 | { |
| 53 | throw std::runtime_error("percentile is not in [0, 100]!"); |
| 54 | } |
| 55 | return toFloat(timings[std::max(all - 1 - exclude, 0)]); |
| 56 | } |
| 57 | |
| 58 | //! |
| 59 | //! \brief Find median in a sorted sequence of timings |
no test coverage detected