本文整理汇总了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;
}
示例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;
}