Example #1
0
void print::Done(std::shared_ptr<Result> x)
{
    celero::console::SetConsoleColor(celero::console::ConsoleColor_Default);
    std::cout << "[     DONE ] ";
    std::cout << x->getExperiment()->getShort() << " ";
    std::cout << celero::timer::ConvertSystemTime(x->getExperiment()->getTotalRunTime()) << " sec.";
    std::cout << " [" << std::scientific << x->getUsPerCall() << " us/call]" << std::fixed <<
              " [" << x->getOpsPerSecond() << " calls/sec]" << std::endl;
}
Example #2
0
void celero::print::TableRowHeader(std::shared_ptr<Result> x)
{
	celero::console::SetConsoleColor(celero::console::ConsoleColor_Default);
	std::cout << PrintColumn(x->getExperiment()->getBenchmark()->getName())
				<< PrintColumn(x->getExperiment()->getName())
				<< PrintColumn(x->getProblemSpaceValue())
				<< PrintColumn(x->getExperiment()->getSamples())
				<< PrintColumn(x->getProblemSpaceIterations());
}
Example #3
0
void print::Baseline(std::shared_ptr<Result> x)
{
    auto baselineGroupName = x->getExperiment()->getBenchmark()->getName();
    if(baselineGroupName.empty() == false)
    {
        celero::console::SetConsoleColor(celero::console::ConsoleColor_Cyan);
        std::cout << "[ BASELINE ] ";
        std::cout << x->getExperiment()->getShort() << " ";
        std::cout << x->getBaselineMeasurement() <<
                  " [SD: " << x->getStatistics()->getStandardDeviation() <<
                  ", V: " << x->getStatistics()->getVariance() <<
                  ", K: " << x->getStatistics()->getKurtosis() << "]" << std::endl;

        celero::console::SetConsoleColor(celero::console::ConsoleColor_Default);
    }
}
Example #4
0
void print::Run(std::shared_ptr<Result> x)
{
    celero::console::SetConsoleColor(celero::console::ConsoleColor_Default);
    std::cout << "[ RUN      ] ";

    if(x->getExperiment()->getResultSize() > 1)
    {
        std::cout << x->getExperiment()->getName() << " @ " << x->getProblemSpaceValue();
    }
    else
    {
        std::cout << x->getExperiment()->getName();
    }

    std::cout << " [" << x->getExperiment()->getSamples() << " samples of " << x->getExperiment()->getCalls() << " calls each.]" << std::endl;
}
Example #5
0
void celero::print::TableRowHeader(std::shared_ptr<Result> x)
{
	celero::console::SetConsoleColor(celero::console::ConsoleColor_Default);
	std::cout << PrintColumn(x->getExperiment()->getBenchmark()->getName())
				<< PrintColumn(x->getExperiment()->getName());

	if(x->getProblemSpaceValue() == static_cast<int64_t>(TestFixture::Constants::NoProblemSpaceValue))
	{
		std::cout << std::fixed << std::right << PrintColumn("Null");
	}
	else
	{
		std::cout << PrintColumn(x->getProblemSpaceValue());
	}

	std::cout << PrintColumn(x->getExperiment()->getSamples())
				<< PrintColumn(x->getProblemSpaceIterations());
}
Example #6
0
void executor::RunExperiments(std::shared_ptr<Benchmark> bmark)
{
	auto experimentSize = bmark->getExperimentSize();

	for(size_t i = 0; i < experimentSize; i++)
	{
		auto e = bmark->getExperiment(i);
		assert(e != nullptr);

		executor::Run(e);
	}
}
Example #7
0
///
/// A local function to support running an individual user-defined function for measurement.
///
void ExecuteProblemSpace(std::shared_ptr<Result> r)
{
	// Define a small internal function object to use to uniformly execute the tests.
	auto testRunner = [r]()
		{
			auto test = r->getExperiment()->getFactory()->Create();
			const auto testTime = test->run(r->getExperiment()->getCalls(), r->getProblemSpaceValue());

			// Save test results
			r->getStatistics()->addSample(testTime);
			r->getExperiment()->incrementTotalRunTime(testTime);
		};

	if(r->getExperiment()->getSamples() > 0)
	{
		for(auto i = r->getExperiment()->getSamples(); i > 0; --i)
		{
			testRunner();
		}  

		r->setComplete(true);
	}
	else
	{
		std::cerr << "Celero: Test \"" << r->getExperiment()->getBenchmark()->getName() << "::" << r->getExperiment()->getName() << "\" must have at least 1 sample.\n";
	}
}
Example #8
0
///
/// A local function to figure out how many iterations and samples are required when the user doesn't specify any.
///
bool AdjustSampleAndIterationSize(std::shared_ptr<celero::ExperimentResult> r)
{
	if(r->getExperiment()->getSamples() == 0)
	{
		// The smallest test should take at least 10x as long as our timer's resolution.
		// I chose "10x" arbitrarily.
		const auto minTestTime = static_cast<int64_t>(celero::timer::CachePerformanceFrequency(true) * 1e6) * 10;

		// Compute a good number to use for iterations and set the sample size to 30.
		auto test = r->getExperiment()->getFactory()->Create();
		auto testTime = int64_t(0);
		auto testIterations = int64_t(1);

		while(testTime < minTestTime)
		{
			const auto runResult = RunAndCatchExc(*test, r->getExperiment()->getThreads(), testIterations, r->getProblemSpaceValue());

			if(runResult.first == false)
			{
				return false; // something bad happened
			}

			testTime = runResult.second;

			if(testTime < minTestTime)
			{
				testIterations *= 2;
			}
		}

		const auto iterations = static_cast<uint64_t>(std::max(static_cast<double>(testIterations), 1000000.0 / testTime));
		auto experiment = r->getExperiment();

		experiment->setIterations(iterations);
		experiment->setSamples(30);

		r->setProblemSpaceValue(r->getProblemSpaceValue(), r->getProblemSpaceValueScale(), iterations);
	}
	return true;
}
Example #9
0
///
/// A local function to support running an individual user-defined function for measurement.
///
bool ExecuteProblemSpace(std::shared_ptr<celero::ExperimentResult> r)
{
	// Define a small internal function object to use to uniformly execute the tests.
	auto testRunner = [r](const bool record) {
		auto test = r->getExperiment()->getFactory()->Create();

		const auto runResult = RunAndCatchExc(*test, r->getExperiment()->getThreads(), r->getProblemSpaceIterations(), r->getProblemSpaceValue());

		if(runResult.first == false)
		{
			// something bad happened
			return false;
		}

		const auto testTime = runResult.second;

		// Save test results
		if(record == true)
		{
			r->getTimeStatistics()->addSample(testTime);
			r->getExperiment()->incrementTotalRunTime(testTime);
		}

		return true;
	};

	if(r->getExperiment()->getSamples() > 0)
	{
		// make a first pass to maybe cache instructions/data or other kinds of fist-run-only costs
		if(testRunner(false) == false)
		{
			r->setFailure(true);
			return false;
		}

		for(auto i = r->getExperiment()->getSamples(); i > 0; --i)
		{
			if(testRunner(true) == false)
			{
				r->setFailure(true);
				return false;
			}
		}

		r->setComplete(true);
	}
	else
	{
		std::cerr << "Celero: Test \"" << r->getExperiment()->getBenchmark()->getName() << "::" << r->getExperiment()->getName()
				  << "\" must have at least 1 sample." << std::endl;
		return false;
	}

	return true;
}
Example #10
0
void ResultTable::add(std::shared_ptr<Result> x)
{
	const auto measurements = std::make_pair(x->getProblemSpaceValue(), x->getUsPerCall());
	this->pimpl->results[x->getExperiment()->getBenchmark()->getName()][x->getExperiment()->getName()].push_back(measurements);
	this->save();
}