如何在Mac OS X C ++程序中记录时间戳? [英] How do I record timestamps in a Mac OS X C++ program?

查看:489
本文介绍了如何在Mac OS X C ++程序中记录时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用图形引擎进行大型仿真.

I'm running a giant simulation / with a graphics engine.

许多事件正在发生.

我想给它们加上时间戳(自程序开始执行以毫秒为单位).

I would like to timestamp them (measured in milliseconds since the start of program execution).

我应该为此使用什么? [什么图书馆?]

What should I be using for this? [What library?]

推荐答案

由于Mac OS X基于Unix,请尝试gettimeofday().它将返回秒和微秒,直至系统时钟的分辨率.

Since Mac OS X is Unix based, try gettimeofday(). It will return seconds and microseconds, up to the resolution of the system clock.

#include <sys/types.h>    
int gettimeofday(struct timeval *tv, struct timezone *tz);

struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* microseconds */
};

这篇关于如何在Mac OS X C ++程序中记录时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆