15 #include "absl/random/internal/randen.h"
21 #include "absl/base/internal/raw_logging.h"
22 #include "absl/random/internal/nanobenchmark.h"
23 #include "absl/random/internal/platform.h"
24 #include "absl/random/internal/randen_engine.h"
25 #include "absl/random/internal/randen_hwaes.h"
26 #include "absl/random/internal/randen_slow.h"
27 #include "absl/strings/numbers.h"
44 static constexpr
size_t kStateSizeT = Randen::kStateBytes /
sizeof(
uint64_t);
45 static constexpr
size_t kSeedSizeT = Randen::kSeedBytes /
sizeof(
uint32_t);
49 struct AbsorbFn :
public T {
53 static constexpr
size_t bytes() {
return sizeof(
seed); }
56 for (
size_t i = 0;
i < num_iters; ++
i) {
64 struct GenerateFn :
public T {
68 static constexpr
size_t bytes() {
return sizeof(
state); }
71 const auto*
keys = this->GetKeys();
72 for (
size_t i = 0;
i < num_iters; ++
i) {
79 template <
typename UInt>
83 static constexpr
size_t bytes() {
return sizeof(
UInt); }
86 for (
size_t i = 0;
i < num_iters - 1; ++
i) {
99 "WARNING: Measurement failed, should not happen when using "
100 "PinThreadToCPU unless the region to measure takes > 1 second.\n");
105 static constexpr
const double kNsPerS = 1e9;
106 static constexpr
const double kMBPerByte = 1.0 / 1048576.0;
108 return printf(
"%20s %8s: %12s ticks; %9s (%9s) %8s\n",
"Name",
"Count",
109 "Total",
"Variance",
"Time",
"bytes/s");
113 for (
size_t i = 0;
i <
n; ++
i) {
115 const double ns_per_call = ns_per_tick * ticks_per_call;
116 const double bytes_per_ns =
bytes / ns_per_call;
117 const double mb_per_s = bytes_per_ns * kNsPerS * kMBPerByte;
119 printf(
"%20s %8zu: %12.2f ticks; MAD=%4.2f%% (%6.1f ns) %8.1f Mb/s\n",
121 results[
i].variability * 100.0, ns_per_call, mb_per_s);
126 template <
typename Op,
size_t N>
132 params.verbose =
false;
133 params.max_evals = 6;
139 void RunAll(
const int argc,
char* argv[]) {
149 const FuncInput unpredictable = (argc != 999);
150 static const FuncInput inputs[] = {unpredictable * 100, unpredictable * 1000};
152 #if !defined(ABSL_INTERNAL_DISABLE_AES) && ABSL_HAVE_ACCELERATED_AES
153 Measure<AbsorbFn<RandenHwAes>>(
"Absorb (HwAes)", inputs);
155 Measure<AbsorbFn<RandenSlow>>(
"Absorb (Slow)", inputs);
157 #if !defined(ABSL_INTERNAL_DISABLE_AES) && ABSL_HAVE_ACCELERATED_AES
158 Measure<GenerateFn<RandenHwAes>>(
"Generate (HwAes)", inputs);
160 Measure<GenerateFn<RandenSlow>>(
"Generate (Slow)", inputs);
163 static const FuncInput inputs1[] = {unpredictable * 1000,
164 unpredictable * 10000};
165 Measure<Engine<uint64_t>>(
"randen_engine<uint64_t>", inputs1);
166 Measure<Engine<uint32_t>>(
"randen_engine<uint32_t>", inputs1);
171 int main(
int argc,
char* argv[]) {