mitsuba-af602c6fd98a/src/tests/test_random.cpp
// Simple benchmark based on the mean test
Simple benchmark based on the mean test
Simple benchmark based on the mean test
void TestRandom::benchmark()
{
	const int N1 = 1000;
	const int N2 = 1000000;
	const Float epsilon = static_cast<Float>(1e-4);
	Float estimate = 0;
	Float current  = 0;
	ref<Random> rnd = new Random;
	for (int i = 0; i < N2; ++i) {
		current += rnd->nextFloat();
	}
	estimate += current / N2;
	ref<Timer> timer = new Timer;
	for (int i = 0; i < N1; ++i) {
		current = 0;
		for (int j = 0; j < N2; ++j) {
			current += rnd->nextFloat();
		}
		estimate += current / N2;
	}
	const Float seconds = timer->getSeconds();
	const int N = N1 * N2;
	Log(EInfo, "Generated %.1fM random numbers in %.2f s (%.3f M-random/s)",
		1e-6 * N, seconds, 1e-6 * N / seconds);
	estimate /= (N1+1);
	assertEqualsEpsilon(estimate, static_cast<Float>(0.5), epsilon);
}
void TestRandom :: benchmark ( ) { const int N1 = 1000 ; const int N2 = 1000000 ; const Float epsilon = static_cast < Float > ( 1e-4 ) ; Float estimate = 0 ; Float current = 0 ; ref < Random > rnd = new Random ; for ( int i = 0 ; i < N2 ; ++ i ) { current += rnd -> nextFloat ( ) ; } estimate += current / N2 ; ref < Timer > timer = new Timer ; for ( int i = 0 ; i < N1 ; ++ i ) { current = 0 ; for ( int j = 0 ; j < N2 ; ++ j ) { current += rnd -> nextFloat ( ) ; } estimate += current / N2 ; } const Float seconds = timer -> getSeconds ( ) ; const int N = N1 * N2 ; Log ( EInfo , " " , 1e-6 * N , seconds , 1e-6 * N / seconds ) ; estimate /= ( N1 + 1 ) ; assertEqualsEpsilon ( estimate , static_cast < Float > ( 0.5 ) , epsilon ) ; }
Simple benchmark based on the mean test
Simple benchmark based on the mean test
// Warm-up // Actual benchmark