boostの時間timer

1626 ワード

C++は、通常、Cのstruct tmおよびtime()を利用する時間および日付の処理能力に欠けている.timerは、timer、progress_timerはタイマクラス、進捗指示クラスはprogress_displayの3つのクラスを含む.
1.timerクラス、内部パッケージはstd::clockで、精度は具体的なコンパイラとオペレーティングシステムに依存します.宣言オブジェクトからオブジェクトの終了までの時間のみを計算できます.
#include <iostream>

#include <boost/timer.hpp>

using namespace std;

using namespace boost;





int main()

{

	timer t;

	cout << "max timespan:" << t.elapsed_max()/3600<<"h"<<endl;//       

	cout << "min timespan:" << t.elapsed_min() << "s" <<endl;//       

	cout << "now time elapsed" << t.elapsed() << "s" << endl;//       

	return 0;

	

}


 2.progress_timerはtimerと継承しますが、呼び出しelapsedを表示する必要はありません.オブジェクトが役割ドメインを終了すると自動的に呼び出されます.
#include <iostream>

#include <boost/progress.hpp>

#include <boost/thread.hpp>

using namespace std;

using namespace boost;





int main()

{

	progress_timer t;



	this_thread::sleep(posix_time::seconds(2));

	

	return 0;

	

}


 3.progress_displayクラスは標準出力で進捗を表示するために使用されます
#include <iostream>

#include <fstream>

#include <vector>

#include <boost/progress.hpp>

using namespace std;

using namespace boost;





int main()

{

	vector<string> vec(100000);

	fstream fs("c:\\test.txt");

	progress_display pd(vec.size());

	for (vector<string>::iterator pos = vec.begin();pos != vec.end();++pos)

	{

		fs << *pos <<endl;

		++pd;

	}

	

	return 0;

	

}