当前位置: 首页>>代码示例>>C++>>正文


C++ StopWatch::EllapsedTime方法代码示例

本文整理汇总了C++中StopWatch::EllapsedTime方法的典型用法代码示例。如果您正苦于以下问题:C++ StopWatch::EllapsedTime方法的具体用法?C++ StopWatch::EllapsedTime怎么用?C++ StopWatch::EllapsedTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StopWatch的用法示例。


在下文中一共展示了StopWatch::EllapsedTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: knots

KnotVector splineknots::CurveDeboorKnotsGenerator::
GenerateKnots(const SurfaceDimension& dimension, double* calculation_time)
{
	StopWatch sw;
	
	KnotVector knots(dimension.knot_count);
	InitializeKnots(dimension, knots);
	auto dfirst = function_.Dx()(dimension.min, 0);
	auto dlast = function_.Dx()(dimension.max, 0);
	KnotVector result(knots.size());

	sw.Start();
	RightSide(knots, abs(dimension.max - dimension.min)
		/ (dimension.knot_count - 1), dfirst, dlast);
	
	auto& rhs = tridiagonal_.Solve(dimension.knot_count-2);
	result[0] = dfirst;
	result[result.size() - 1] = dlast;
	memcpy(&result.front() + 1, &rhs.front(), rhs.size());
	sw.Stop();
	
	if (calculation_time != nullptr)
	{
		*calculation_time = sw.EllapsedTime();
	}
	return result;
}
开发者ID:vilorez,项目名称:VKDiplom-master,代码行数:27,代码来源:CurveDeBoorKnotsGenerator.cpp

示例2: Loop

void MulVsDiv::Loop()
{
	StopWatch sw;

	const int length = 256;
	const int loops = 1e7;
	std::cout << "Simple loop:\n---" << std::endl;
	double a[length], b[length], c[length];
	auto ignoreit = 0.0;

	ResetArrays(length, a, b, ignoreit);
	sw.Start();
	for (size_t l = 0; l < loops; l++)
	{
		// MSVC cannot vectorize this loop (message 1300).
		// However, if this loop will not be nested in, autovectorization will happen.
		// Same condition apply for mul/div/rcp loops

		// ICL does not have this issue, but to provide both vectorized and nonvectorized comparison 
		// i specifically disabled vectorization in this method
#pragma novector
#pragma loop( no_vector )
		for (int i = 0; i < length; ++i)
		{
			c[i] = a[i] + b[i];
		}
	}
	sw.Stop();
	auto add_time = sw.EllapsedTime();
	std::cout << "Addition: " << add_time << std::endl;
	ignoreit -= c[(rand() % static_cast<int>(length))];
	ResetArrays(length, a, b, ignoreit);

	sw.Start();
	for (size_t l = 0; l < loops; l++)
	{
#pragma novector
#pragma loop( no_vector )
		for (int i = 0; i < length; ++i)
		{
			c[i] = a[i] * b[i];
		}
	}
	sw.Stop();
	auto mul_time = sw.EllapsedTime();
	std::cout << "Multiplication: " << mul_time << std::endl;
	ignoreit -= c[(rand() % static_cast<int>(length))];
	ResetArrays(length, a, b, ignoreit);

	sw.Start();
	for (size_t l = 0; l < loops; l++)
	{
#pragma novector
#pragma loop( no_vector )
		for (int i = 0; i < length; ++i)
		{
			c[i] = a[i] / b[i];
		}
	}
	sw.Stop();
	auto div_time = sw.EllapsedTime();
	ignoreit -= c[(rand() % static_cast<int>(length))];
	ignoreit += a[(rand() % static_cast<int>(length))] + b[(rand() % static_cast<int>(length))];
	std::cout << "Division: " << div_time << std::endl;
	std::cout << "Addition faster than multiplication: " << static_cast<double>(mul_time) / static_cast<double>(add_time) << std::endl;
	std::cout << "Multiplication faster than division: " << static_cast<double>(div_time) / static_cast<double>(mul_time) << std::endl;
	std::cout << "Just ignore it: " << ignoreit << std::endl << std::endl;
}
开发者ID:vilorez,项目名称:VKDiplom-master,代码行数:68,代码来源:MulVsDiv.cpp


注:本文中的StopWatch::EllapsedTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。