我是靠谱客的博主 真实冬日,这篇文章主要介绍gettimeofday函数的简单使用,现在分享给大家,希望可以做个参考。

#include <iostream>
#include <sys/time.h>
#include <cstdio>
#include <unistd.h>

using namespace std;

void fun()
{
	sleep(2);
}



int main()
{
	struct timeval tp;
	struct timeval tp1;
	int g_time_start;
	int g_time_end;
	gettimeofday(&tp,NULL);
	g_time_start = tp.tv_sec * 1000 + tp.tv_usec/1000;

	fun();
	gettimeofday(&tp1,NULL);
	g_time_end = tp1.tv_sec * 1000 + tp1.tv_usec/1000;

	cout << g_time_end - g_time_start << endl;
	
	return 0;
}

可用来计算执行某个操作消耗的时间

最后

以上就是真实冬日最近收集整理的关于gettimeofday函数的简单使用的全部内容,更多相关gettimeofday函数内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部