//
//文件名: testclk.h
//作者: 口天草芳
//编写日期:2002.9.18
//编写目的:声明并实现一个测试代码执行时间的类
//
#ifndef TESTCLK_H
#define TESTCLK_H
#include <time.h>
const int CLOCK_SEC=1000;
class Testclk
{
double timestart; //定义程序开始时间
double timeend; //定义程序结束时间
double protime; //进程的执行时间
public:
Testclk();
double ProcessStart(); //进程开始计时
double ProcessEnd(); //进程结束计时
double ShowTime(); //显示进程执行时间
~Testclk();
};
//下面的代码为成员函数的实现
Testclk::Testclk()
{
timestart=0.0;
timeend=0.0;
protime=0.0;
}
double Testclk::ProcessStart()
{
cout<<"开始计时:"<<endl;
timestart=(double)clock()/(double)
CLOCK_SEC;
return timestart;
}
double Testclk::ProcessEnd()
{
cout<<"计时结束: "<<endl;
timeend=(double)clock()/(double)
CLOCK_SEC;
protime=timeend-timestart;
return protime;
}
double Testclk::ShowTime()
{
cout<<"进程执行时间为:"<<protime<<endl;
}
Testclk::~Testclk()
{
cout<<"测试结束:-D"<<endl;
}
#endif
测试代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "testclk.h"
int main(int argc, char *argv[])
{
Testclk testob;
testob.ProcessStart();
cout<<"程序正在执行..."<<endl;
Sleep(2000);
cout<<"程序完成!!"<<endl;
testob.ProcessEnd();
testob.ShowTime();
system("PAUSE");
return 0;
}
//文件名: testclk.h
//作者: 口天草芳
//编写日期:2002.9.18
//编写目的:声明并实现一个测试代码执行时间的类
//
#ifndef TESTCLK_H
#define TESTCLK_H
#include <time.h>
const int CLOCK_SEC=1000;
class Testclk
{
double timestart; //定义程序开始时间
double timeend; //定义程序结束时间
double protime; //进程的执行时间
public:
Testclk();
double ProcessStart(); //进程开始计时
double ProcessEnd(); //进程结束计时
double ShowTime(); //显示进程执行时间
~Testclk();
};
//下面的代码为成员函数的实现
Testclk::Testclk()
{
timestart=0.0;
timeend=0.0;
protime=0.0;
}
double Testclk::ProcessStart()
{
cout<<"开始计时:"<<endl;
timestart=(double)clock()/(double)
CLOCK_SEC;
return timestart;
}
double Testclk::ProcessEnd()
{
cout<<"计时结束: "<<endl;
timeend=(double)clock()/(double)
CLOCK_SEC;
protime=timeend-timestart;
return protime;
}
double Testclk::ShowTime()
{
cout<<"进程执行时间为:"<<protime<<endl;
}
Testclk::~Testclk()
{
cout<<"测试结束:-D"<<endl;
}
#endif
测试代码:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "testclk.h"
int main(int argc, char *argv[])
{
Testclk testob;
testob.ProcessStart();
cout<<"程序正在执行..."<<endl;
Sleep(2000);
cout<<"程序完成!!"<<endl;
testob.ProcessEnd();
testob.ShowTime();
system("PAUSE");
return 0;
}