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; }

      

  • 相关阅读:
    阿里代码检查工具
    SpringCloud 服务通信方法
    Apache ab简单使用
    H5 webSocket使用
    Java list去重 取重
    解决 spring boot Failed to decode downloaded font
    Pycharm设置快捷方式
    环境变量与文件的查找
    Linux基础
    VIM中文乱码解决
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4432542.html
Copyright © 2011-2022 走看看