SilverStar

专注于C++技术
随笔 - 2, 文章 - 0, 评论 - 0, 引用 - 0
数据加载中……

Test

  1: #include <ctime>
  2: #include <iostream>
  3: #include <chrono>
  4: #include <thread>
  5: #include <iomanip>
  6: using namespace std;
  7: // the function f() does some time-consuming work
  8: void f()
  9: {
 10: 	volatile double d=0;
 11: 	for(int n=0; n<1000; ++n)
 12: 		printf("%d ",n);
 13: 	printf("\n");
 14: }
 15: int main()
 16: {
 17: 	std::clock_t c_start = std::clock();
 18: 	auto t_start = std::chrono::high_resolution_clock::now();
 19: 	std::thread t1(f);
 20: 	std::thread t2(f); // f() is called on two threads
 21: 	t1.join();
 22: 	t2.join();
 23: 
 24: 
 25: 	std::clock_t c_end = std::clock();
 26: 	auto t_end = std::chrono::high_resolution_clock::now();
 27: 	std::cout << "CPU time used: "
 28: 		<< 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC
 29: 		<< " ms\n";
 30: 	std::cout << "Wall clock time passed: "
 31: 		<< std::chrono::duration_cast<std::chrono::milliseconds>(t_end - t_start).count()
 32: 		<< " ms\n";
 33: 
 34: 
 35: 
 36: }
 37: 

posted on 2012-09-25 20:52 lethe555 阅读(188) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理