计算一段程序的执行时间

2014-11-24 00:12:13 · 作者: · 浏览: 5
 / 计算程序执行时间.cpp : Defines the entry point for the console application.   
//   
  
#include "stdafx.h"   
#include    
#include    
#include    
void do_something()  
{  
    for(int i=0;i<100000;i++)  
        for(int j=0;j<10000;j++)  
            ;  
}  
int main(int arg,char ** argv)  
{  
    clock_t start=clock();  
    do_something();  
    clock_t end=clock();  
    float time=(float)(end-start)/CLOCKS_PER_SEC;  
    printf("%fs\n",time);  
    system("pause");  
    return 0;  
}  

// 计算程序执行时间.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
#include #include void do_something() { for(int i=0;i<100000;i++) for(int j=0;j<10000;j++) ; } int main(int arg,char ** argv) { clock_t start=clock(); do_something(); clock_t end=clock(); float time=(float)(end-start)/CLOCKS_PER_SEC; printf("%fs\n",time); system("pause"); return 0; }