写算法观察复杂度和用时,想着打时间戳来着,搜来搜去发现我CSDN上居然都是一些水文章,十位时间戳精准到秒谁不会?
收集信息自己写一篇13位时间戳打法,仅供参考:
#include<bits/stdc++.h>
#include<sys/timeb.h>
#include<windows.h>
using namespace std;
int main(){
timeb t1,t2;
ftime(reinterpret_cast<timeb *>(&t1));
//测试代码放在这里
ftime(reinterpret_cast<timeb *>(&t2));
cout<<t1.time*1000+t1.millitm-t2.time*1000-t2.millitm;
}
timeb.h是对time.h的补充,刚开始include<timeb.h>还找不到这个包,根据Clion的提示改为#include<sys/timeb.h>就OK了;
以下是timeb的结构体定义:
struct timeb
{
time_t time; //十位时间戳
unsigned short millitm; //毫秒计数,不过只有毫秒,可以结合十位时间戳生成13位时间戳
short timezone; //没测
short dstflag; //没测
};
太忙了,没测的有机会再测吧