// Copyright 2020 Google LLC. All Rights Reserved. #ifndef WHITEBOX_BENCHMARKING_MEASUREMENT_H_ #define WHITEBOX_BENCHMARKING_MEASUREMENT_H_ #include #include #include #include #include #include namespace widevine { using Clock = std::chrono::high_resolution_clock; using Period = std::chrono::microseconds; class Timer { public: void Reset(); Period Get() const; private: Clock::time_point start_; }; struct Throughput { size_t bytes; uint64_t microseconds; uint64_t bits_per_second; Throughput(); Throughput(const Period& duration, size_t bytes); }; class Sampler { public: class Percentile { public: Percentile(const std::vector& samples) : samples_(samples) { std::sort(samples_.begin(), samples_.end()); }; const Period& Get(size_t percentile) const; private: std::vector samples_; }; void Push(const Period& period); Percentile Percentiles() const { return Percentile(samples_); } size_t SampleSize() const { return samples_.size(); } private: std::vector samples_; }; void PrettyPrint(const std::string& title, const Throughput& throughput, size_t bytes_per_call); void PrettyPrint(const std::string& title, const Sampler& samples, size_t sample_input_size); } // namespace widevine #endif // WHITEBOX_BENCHMARKING_MEASUREMENT_H_