码迷,mamicode.com
首页 > 编程语言 > 详细

算法时间测试

时间:2016-07-15 00:44:31      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 //算法时间测试 基准法(定量分析) 大O法(定性分析)
 2 //以下是基准法
 3 #include "iostream"
 4 #include "cstdio"
 5 #include "ctime"
 6 #include "windows.h"
 7 using namespace std;
 8 int main()
 9 {
10     //法一
11     clock_t start1,end1;//clock_t  需头文件#include "ctime"
12     double duration1 ;
13 
14     start1=clock();//返回程序运行到此位置时所用毫秒数
15     ::Sleep(3000);//延时函数 参数为毫秒  头文件#include "windows.h"   注俩冒号和大写S
16     end1=clock();
17     duration1=(double)(end1-start1)/CLOCKS_PER_SEC;//为输出秒,毫秒化秒
18     cout<<"The clock_t  time is  "<<duration1<<"S"<<endl;
19 
20 
21 
22     //法二
23     time_t start2,end2;
24 
25     start2=time(0);//获取的是从1970 1 1 0:0:0 到现在的秒数(注意单位为秒)
26     ::Sleep(3000);
27     end2=time(0);
28     double duration2=end2-start2;
29     cout<<"The time_t   time is  "<<duration2<<"S"<<endl;
30 }
View Code

 

算法时间测试

标签:

原文地址:http://www.cnblogs.com/kimsimple/p/5672091.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!