您的位置:首页 > 其它

查看运行时间函数--比较运行速度

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: