Ubuntu C/C++ 获取系统时间

使用OpenCV处理图像的时,可以使用linux系统的<sys/time.h>头文件获取图像处理时间。

#include <sys/time.h>

Code Example:

#include <stdio.h>
#include <sys/time.h>

int main(int argc, char **argv) {
  struct timeval tv;
  gettimeofday(&tv,NULL);
  printf("second:%ld \n",tv.tv_sec); //秒
  printf("millisecond:%ld \n",tv.tv_sec*1000 + tv.tv_usec/1000); //毫秒
  printf("microsecond:%ld \n",tv.tv_sec*1000000 + tv.tv_usec); //微秒
  return 0;
}

Result:

second:1545039819 
millisecond:1545039819224 
microsecond:1545039819224055 

gettimeofday函数

Name: gettimeofday
Prototype: int gettimeofday (struct timeval *tp, struct timezone *tzp)
Description:
The gettimeofday function returns the current calendar time as the elapsed time since the epoch in the struct timeval structure indicated by tp. ( for a description of struct timeval). Information about the time zone is returned in the structure pointed at tzp. If the tzp argument is a null pointer, time zone information is ignored.

The return value is 0 on success and -1 on failure. The following errno error condition is defined for this function.

------------------------------------------------------20190603--------------------------------------------------------------------------------------------------

在ROS机器人中如何使用

  struct timeval start, end;
  double start_t, end_t, t_diff;

  gettimeofday(&start, NULL);
  for(unsigned int i = 0; i < 2000; ++i){
    pg.insert(point);
  }
  gettimeofday(&end, NULL);
  start_t = start.tv_sec + double(start.tv_usec) / 1e6;
  end_t = end.tv_sec + double(end.tv_usec) / 1e6;
  t_diff = end_t - start_t;
  printf("%%Insertion Time: %.9f \n", t_diff);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值