其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
[C++]C++中的時間

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

C++中的時間

 


#include <stdio.h>

#include <tchar.h>

#include <string>

#include <iostream>

#include <time.h>

#include <conio.h>

#include <dos.h>

 

using namespace std;

 

int _tmain(int argc, _TCHAR* argv[])

{

     clock_t start,end;

     //宏定義:__DATE____TIME____FILE____LINE__,表示在代碼編譯時的信息。

     string dateCode = __DATE__;      //文件編譯時的日期。

     string timeCode = __TIME__;      //文件編譯時的時間。

 

     cout<<"Creat the software of date:"<<dateCode<<endl;

     cout<<"Creat the software of time:"<<timeCode<<endl;

 

     start = clock();   //程序運行到這裡開始統計CPU運行時間,此時值為0

     _getch(); //按下任意一鍵時程序繼續執行。

     end = clock();         //按下鍵後統計時間。

 

     cout<<"Press any key to continue"<<endl;

     //由於endstart為毫秒,故除以CLK_TCK轉為秒值。

     cout<<"Program run time: "<<(end - start)/CLK_TCK<<" Sceond."<<endl;

     return 0;

}

 


可以用clock來統計程序運行的時間長短。

time返回从1970110时到现在的秒数,即系统时间。

clock是自进程启动后此进程使用cpu的总毫秒数,常用来测试任务执行的速度。




相关文章

相关软件