text
stringlengths
0
2.2M
LOOP5_ASSERT(i, j, rand_int, numbers[i], numbers[j],
numbers[j] != numbers[i]);
}
for (int b = 0; b < 15; ++b) {
cnt += rand_int & 1;
rand_int >>= 1;
if (veryVerbose) { P(cnt) }
}
}
double expected = (NUM_ITERATIONS * 15) / 2;
ASSERT(cnt < (expected * 1.2));
ASSERT(cnt > (expected * 0.8));
} break;
case -2: {
// --------------------------------------------------------------------
// PERFORMANCE: 'getRandomBytes'
//
// Concerns:
// Measure the effect of requesting larger random numbers per
// request from the blocking random generator.
//
// Plan:
// Request a large number of random numbers to consume the entropy
// on process start-up. Next, request the same total number of
// bytes, each time changing the size of the request, measure the
// time to complete each request.
//
// Testing:
// PERFORMANCE: 'getRandomBytes'
// --------------------------------------------------------------------
if (verbose) cout << endl
<< "PERFORMANCE: 'getRandomBytes'" << endl
<< "=============================" << endl;
bsls::Stopwatch s;
const int NUM_ITERATIONS = 4;
const int MAX_GRANUALARITY = 1 << NUM_ITERATIONS;
unsigned char buffer[MAX_GRANUALARITY] = { };
unsigned char prev_buffer[MAX_GRANUALARITY] = { };
for (int granularity = 1;
granularity < MAX_GRANUALARITY;
granularity <<= 1) {
memcpy(prev_buffer, buffer, MAX_GRANUALARITY);
s.start(true);
int i;
for (i = 0; i <= MAX_GRANUALARITY; i += granularity) {
if (veryVerbose) { P(i) }
ASSERT(0 == Util::getRandomBytes(buffer + granularity,
granularity));
}
s.stop();
LOOP2_ASSERT(granularity,
i,
0 != memcmp(buffer, prev_buffer, MAX_GRANUALARITY));
double time = s.accumulatedUserTime() + s.accumulatedSystemTime() +
s.accumulatedWallTime();
P_(granularity) P(time);
s.reset();
}
} break;
case -3: {
// --------------------------------------------------------------------
// PERFORMANCE: 'getRandomBytesNonBlocking'
//
// Concerns:
// Measure the effect of requesting larger random numbers per
// request from the non-blocking random generator.
//
// Plan:
// Request a large number of random numbers to consume the entropy
// on process start-up. Next, request the same total number of
// bytes, each time changing the size of the request, measure the
// time to complete each request.
//
// Testing:
// PERFORMANCE: 'getRandomBytesNonBlocking'
//---------------------------------------------------------------------
if (verbose)
cout << endl
<< "PERFORMANCE: 'getRandomBytesNonBlocking'" << endl
<< "========================================" << endl;
int rand_int;
for (int i = 0; i < 15; ++i) {
if (veryVerbose) { P(i) }
ASSERT(0 == Util::getRandomBytesNonBlocking(
reinterpret_cast<unsigned char *>(&rand_int),
sizeof rand_int));
}
bsls::Stopwatch s;
const int NUM_ITERATIONS = 4;
const int MAX_GRANUALARITY = 1 << NUM_ITERATIONS;
unsigned char buffer [MAX_GRANUALARITY] = { };
unsigned char prev_buffer[MAX_GRANUALARITY] = { };
for (int granularity = 1;
granularity < MAX_GRANUALARITY;
granularity <<= 1) {
memcpy(prev_buffer, buffer, MAX_GRANUALARITY);