C++如何测定一个程序的运行时间(毫秒)

C++如何测定一个程序的运行时间(毫秒),第1张

几条语句,没有循环,毫秒级有点大了

#include <windowsh>

#include <stdioh>

 

int main()

{

    DWORD start,

stop;

    start =

GetTickCount();

    Sleep(3000);

    stop =

GetTickCount();

    printf("time: %lld ms\n",

stop - start);

    return 0;

}

~

下面是保留两位的

sprintf(time, "%s%02d", tstr, tmstv_usec/100);

下面是保留三位的

sprintf(time, "%s%03d", tstr, tmstv_usec/1000);

#include <cstdio>

#include <ctime>

using namespace std;

/ run this program using the console pauser or add your own getch, system("pause") or input loop /

void printTime() {

  struct tm t;   //tm结构指针

time_t now;  //声明time_t类型变量

time(&now);      //获取系统日期和时间

localtime_s(&t, &now);   //获取当地日期和时间

   //格式化输出本地时间

printf("年-月-日-时-分-秒:%d-%d-%d %d:%d:%d\n", ttm_year + 1900, ttm_mon + 1, ttm_mday, ttm_hour, ttm_min, ttm_sec);

}

int main(int argc, char argv) {

printTime();

}

以上就是关于C++如何测定一个程序的运行时间(毫秒)全部的内容,包括:C++如何测定一个程序的运行时间(毫秒)、C语言打印毫秒、如何用C语言编写一个显示时间的函数,要求时间显示精度到毫秒级别。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9509285.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存