Linux 高性能 获取时间

基础 常用时间函数 从The Linux Programming Interface 上看,获取时间最常用的函数是 gettimeofday,常见的中间件也是用该函数么? 1 2 3 #include <sys/time.h> int gettimeofday(struct timeval *tv, struct timezone *tz); Returns 0 on success, or –1 on error Redis 扫了下redis的命令,发现redis有个time command. 调用该command能够返回当前服务器的时间戳,从redis源码 )上看,redis也是调用了gettimeofday获取当前的时间 1 2 3 4 5 6 7 8 9 10 void timeCommand(client *c) { struct timeval tv; gettimeofday(&tv,NULL); addReplyArrayLen(c,2); addReplyBulkLongLong(c,tv.tv_sec); addReplyBulkLongLong(c,tv.tv_usec); }… Continue reading Linux 高性能 获取时间