zoukankan      html  css  js  c++  java
  • C++获取当前时间和计算程序运行时间的方法

    C++获取当前时间和计算程序运行时间的方法 
    获取当前时间: 
    #include <iostream> 
    #include <Windows.h>  
    
    using namespace std;  
    
    int main() { 
       	SYSTEMTIME sys;     
    	GetLocalTime(&sys);   
    	cout<<sys.wYear<<"年";     
    	cout<<sys.wMonth<<"月";     
    	cout<<sys.wDay<<"日";     
    	cout<<sys.wHour<<"时";     
    	cout<<sys.wMinute<<"分";     
    	cout<<sys.wSecond<<"秒";     
    	cout<<sys.wMilliseconds<<"毫秒"; 
    	cout<<",星期"<<sys.wDayOfWeek<<endl;  
       	return 0;
    } 
      
    计算程序运行时间 方法一: 
    
    #include<iostream.h>
    #include<time.h>
    void main()
    {
       clock_t start,finish;
       double totaltime;
       start=clock();

       …… //把你的程序代码插入到这里面

       finish=clock();
       totaltime=(double)(finish-start) / CLOCKS_PER_SEC;  //CLOCKS_PER_SEC注意一下
       cout<<" 此程序的运行时间为"<<totaltime<<"秒!"<<endl;
    }

    计算程序运行时间 方法二: #include <iostream> #include <Windows.h> //关键 using namespace std; int main() { LONGLONG start, finish; LONGLONG totalTime; start = GetTickCount(); //需要测试运行时间的代码段放在这 finish = GetTickCount(); totalTime = finish - start; cout<<"花费"<<totalTime<<"毫秒"<<endl; return 0; }

      

  • 相关阅读:
    信号量Semaphore
    进程锁Lock
    创建多进程Process
    什么是进程?什么是线程?进程和线程之间的区别是什么?
    Git命令
    xss攻击问题以及如何防范
    ORM跨表查询问题
    for循环将字典添加到列表中出现覆盖前面数据的问题
    Linux源码的目录结构
    嵌入式中 MMU的功能
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4432542.html
Copyright © 2011-2022 走看看