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


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

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


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

示例1: SleepFor

	void ThreadBoost::SleepFor(millis_t millis, bool ensureSleepForCorrectTime)
	{
		
		if(ensureSleepForCorrectTime){
			StopWatch sw;
			millis_t remain = millis;
			do{
				boost::this_thread::sleep(boost::posix_time::milliseconds(remain));
				millis_t remain = millis - sw.Elapsed(false);
				if(remain <= 0) break;
				boost::this_thread::yield();
			}while(true);
		}else{
			boost::this_thread::sleep(boost::posix_time::milliseconds(millis));
		}

	}
开发者ID:diverger,项目名称:dnp3,代码行数:17,代码来源:ThreadBoost.cpp

示例2: Test

bool Test(int n, int ix)
{
	// Test of the updating Cholesky factorization of the random SPD test matrix after the symmetric column/row deletion
	// Get a Test matrix
	SetPrintParams(2, 0);
	cout << endl << n << " x " << n << " Test matrix" << endl;
	cout << "Deleting row/column: " << ix << endl;

	SetPrintParams(7, 3);

	SpdMatrixT orig(n * (n + 1) / 2);
	SpdMatrixT reduced(n * (n + 1) / 2);

	StopWatch sw;
	if ( GetRandomMatrix(n, ix - 1, orig, reduced) != Status::Success )
	{
		cout << "Cannot get a test matrix, incorrect input parameter (matrix dimension)." << endl;
		return false;
	}
	cout <<"Time of the matrices generating = "  << sw.Elapsed() << " (s)\n";

	SpdCholT cholReduced(std::move(reduced), n - 1); 
	sw.Restart();
	Status rc = cholReduced.Factorize();
	cout <<"Time of the matrix factorizing = "  << sw.Elapsed() << " (s)\n";
	if ( rc != Status::Success )
	{
		cout << "Cannot factorize the Reduced test matrix, it is not positive-definite one. rc = " << rc << endl;
		return false;
	}
	cout << "The Reduced test matrix is factorized, rc = " << rc << endl; 

	SpdCholT cholOrig(std::move(orig), n); 
	rc = cholOrig.Factorize();
	if ( rc != Status::Success )
	{
		cout << "Cannot factorize the original test matrix, it is not positive-definite one. rc = " << rc << endl;
		return false;
	}
	cout << "The Original test matrix is factorized, rc = " << rc << endl;

	// Get assessment of the test matrix condition number
	cout.unsetf(std::ios::fixed);
	SetPrintParams(7, 1, std::ios::scientific);
	cout << "The Original matrix reciprocal condition number = " << cholOrig.GetRCond() << endl;

	sw.Restart();
	rc = cholOrig.UpdateDel(ix - 1);
	cout <<"Time of the matrix factor recalculating = "  << sw.Elapsed() << " (s)\n";
	if ( rc != Status::Success )
	{
		cout << "Cannot calculate the updated Cholesky factor of the Test matrix. rc = " << rc << endl;
		return false;
	}
	cout << "The updated Cholesky factor of the Original matrix is calculated. rc = " << rc << endl;

    SpdMatrixT diff(cholOrig.GetMatrix());
	SpdMatrixT fac = cholReduced.GetMatrix();

	int n1 = n - 1;
	Size_T sz = n1 * (n1 + 1) / 2;
	for ( Size_T i = 0; i < sz; ++i ) 
	{
		diff[i] -= fac[i];
	}

	Helper1T hlp;
	auto rn = hlp.GetVectorNorm2(sz, diff);
	cout << "Norm of diference of the Orginal(recalculated) and Reduced factors = " << rn << endl;

	VectorT b1(n1, 1);
	rc = cholReduced.Solve(b1);

	VectorT b2(n1, 1);
	rc = cholOrig.Solve(b2);
	for ( Size_T i = 0; i < n1; ++i ) 
	{
		b1[i] -= b2[i];
	}
	rn = hlp.GetVectorNorm2(n1, b1);
	cout << "Norm of diference of the solutions = " << rn << endl;

	return true;
}
开发者ID:nettvor,项目名称:choltest,代码行数:84,代码来源:choltest.cpp


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