Files
whitebox/benchmarking/measurements.h
Aaron Vaage 5d90e8d89b Benchmarking and Unmasking
In this code drop we introduce the benchmarking tests that allow us to
compare the performance of different implementations. Like the other
tests, any implementation can link with them to create their own
binary.

There are two types of benchmarks:
  1 - Throughput, which measures the speed that a function can process
      information (bits per second). These are used for AEAD decrypt
      and license white-box decrypt functions.
  2 - Samples, which measures the min, 25% percentile, median, 75%
      percentile, and max observed values. These is used for all other
      functions as a way to measure the execute duration of a call.

The other change in this code drop is the update to the unmasking
function to only unmask a subset of the bytes in the masked buffer.
This was added to better align with the decoder behaviour in the CDM.
2020-06-24 15:30:50 -07:00

73 lines
1.4 KiB
C++

// Copyright 2020 Google LLC. All Rights Reserved.
#ifndef WHITEBOX_BENCHMARKING_MEASUREMENT_H_
#define WHITEBOX_BENCHMARKING_MEASUREMENT_H_
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <chrono>
#include <string>
#include <vector>
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<Period>& samples) : samples_(samples) {
std::sort(samples_.begin(), samples_.end());
};
const Period& Get(size_t percentile) const;
private:
std::vector<Period> samples_;
};
void Push(const Period& period);
Percentile Percentiles() const { return Percentile(samples_); }
size_t SampleSize() const { return samples_.size(); }
private:
std::vector<Period> 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_