查看运行时间函数--比较运行速度
2012-08-11 09:07
309 查看
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <time.h> #include <string.h> #include <algorithm> using namespace std; class Time { public: void Start() //开始计时 { start_time=clock(); } int End() //结束计时,返回消耗的时间。以ms为单位 { return clock()-start_time; } private: clock_t start_time; }; const int MAX = 10000000; char a[MAX]; int main() { int i; char to = '/0'; cout<<"to="<<to<<endl; Time t; t.Start(); clock(); memset(a,to,sizeof(a)); cout << t.End() << endl; t.Start(); clock(); for(i=0; i<MAX; i++) a[i] = to; for(i=0; i<MAX; i++) cout<<a[i]<<" "; cout << t.End() << endl; t.Start(); clock(); fill(a,a+MAX,to); cout << t.End(); system("pause"); return 0; }
相关文章推荐
- vs2008查看函数运行时间的方法。
- 简单的查看函数时间运行类
- 分别使用递归方法和非递归方法求斐波那契数列,并比较两者的运行速度(测量代码运行时间)
- 比较“+”,insert( )和append( )的速度,利用循环向列表中增加10000个元素,比较几种方法的运行时间。
- 算法运行时间、logN、NlogN 之间的比较
- Linux下如何查看系统启动时间和运行时间
- IAR 硬件仿真查看运行时间
- 查看代码运行时间
- CCS查看DSP程序运行时间
- 查看mysql语句运行时间
- 实例说明:多进程和多线程 运行时间比较
- Linux下如何查看系统启动时间和运行时间
- linux下查看系统运行时间和最近一次的开机启动时间
- 测量程序运行时间的几个函数
- oracle 查看启动时间和运行时间
- 计算php页面运行时间的函数
- 不同时间复杂度函数比较
- golang思考之运行速度之函数调用
- gdb如何调试每个函数运行的时间