23 #include "gmock/gmock.h"
24 #include "gtest/gtest.h"
25 #include "absl/strings/str_cat.h"
31 namespace profiling_internal {
50 return exp(-1.2337141 / z) / sqrt(z) *
53 (0.0649821 - (0.0347962 - (0.011672 - 0.00168691 *
z) * z) *
z) *
60 (0.43424 - (0.082433 - (0.008056 - 0.0003146 * z) * z) * z) * z) *
71 (1705.091 - (1950.646 - (1116.360 - 255.7844 * x) * x) * x) * x) *
75 double cutoff = 0.01265 + 0.1757 /
n;
77 double t =
x / cutoff;
78 t = sqrt(t) * (1 -
t) * (49 * t - 102);
79 return t * (0.0037 / (
n *
n) + 0.00078 / n + 0.00006) /
n;
81 double t = (
x - cutoff) / (0.8 - cutoff);
83 (6.54034 - (14.6538 - (14.458 - (8.259 - 1.91864 *
t) * t) *
t) * t) *
85 return t * (0.04213 + 0.01365 /
n) / n;
97 int n = random_sample.size();
99 for (
int i = 0;
i <
n;
i++) {
100 ad_sum += (2 *
i + 1) *
101 std::log(random_sample[i] * (1 - random_sample[n - 1 - i]));
103 double ad_statistic = -
n - 1 /
static_cast<double>(
n) * ad_sum;
118 TEST(ExponentialBiasedTest, CoinTossDemoWithGetSkipCount) {
119 ExponentialBiased eb;
120 for (
int runs = 0; runs < 10; ++runs) {
121 for (
int flips = eb.GetSkipCount(1); flips > 0; --flips) {
127 for (
int i = 0;
i < 10000000;
i += 1 + eb.GetSkipCount(1)) {
130 printf(
"Heads = %d (%f%%)\n", heads, 100.0 * heads / 10000000);
133 TEST(ExponentialBiasedTest, SampleDemoWithStride) {
134 ExponentialBiased eb;
135 int stride = eb.GetStride(10);
137 for (
int i = 0;
i < 10000000; ++
i) {
140 stride = eb.GetStride(10);
143 printf(
"Samples = %d (%f%%)\n", samples, 100.0 * samples / 10000000);
149 TEST(ExponentialBiasedTest, TestNextRandom) {
150 for (
auto n : std::vector<int>({
159 for (
int i = 1;
i <= 20;
i++) {
162 std::vector<uint64_t> int_random_sample(n);
164 for (
int i = 0;
i <
n;
i++) {
165 int_random_sample[
i] =
x;
169 std::sort(int_random_sample.begin(), int_random_sample.end());
170 std::vector<double> random_sample(n);
172 for (
int i = 0;
i <
n;
i++) {
174 static_cast<double>(int_random_sample[
i]) / max_prng_value;
179 <<
"prng is not uniform: n = " <<
n <<
" p = " << ad_pvalue;
185 TEST(ExponentialBiasedTest, InitializationModes) {
189 #ifdef ABSL_HAVE_THREAD_LOCAL
190 thread_local ExponentialBiased eb_thread;
194 ExponentialBiased eb_stack;