网站首页 > 基础教程 正文
作用
clock_gettime是基于Linux C语言的时间函数,他可以用于计算精度和纳秒。
//头文件
#include <time.h>
//函数原型
int clock_gettime( clockid_t clock_id,struct timespec * tp );
// timespec 结构体
struct timespec {
__time_t tv_sec; /* 秒 */
__syscall_s long_t tv_nsec; /* 纳秒 */
};
clock_id: 是指使用时钟的类型
- CLOCK_REALTIME:是指系统时间,随着系统时间的改变而改变。系统时钟会被用户而改变。
- CLOCK_MONOTONIC:指从系统启动时开始计时。不受系统影响,也不会被用户改变。
- CLOCK_PROCESS_CPUTIME_ID:指这个进程运行到当前代码时,系统花费的时间。
- CLOCK_THREAD_CPUTIME_ID:指这个线程运行到当前代码时,系统花费的时间。
使用方法
#include<stdio.h>
#include<time.h>
int main(){
struct timespec now;
clock_gettime(CLOCK_MONOTONIC,&now);
printf("Seconds = %ld \t Nanoseconds = %ld\n",, now.tv_sec, now.tv_nsec);
return 0;
}
- 上一篇: 在 C++ 中 在C中数组下标是什么类型
- 下一篇: OpenCV4 C++学习 必备基础语法知识二
猜你喜欢
- 2024-10-19 Python3 datetime模块指南:日期时间操作、时区管理与实战案例
- 2024-10-19 C++及数据结构复习笔记,类和对象很简单?为啥好多程序员还不会
- 2024-10-19 Linux时间和日期 linux 时间 表示方法
- 2024-10-19 C/C++的8种时间度量方式以及代码片段
- 2024-10-19 Python实战:使用 datetime模块处理时间日期的全方位指南
- 2024-10-19 C++编程的 42 条建议(四) c++编程100例
- 2024-10-19 mount with noatime - 合理关闭atime提高服务器性能
- 2024-10-19 linux下连续三次fork()——深度理解进程创建函数
- 2024-10-19 C函数time和clock的计时区别 c计时器函数
- 2024-10-19 win进程弹出Microsoft Visual C++ Runtime Library的解决办法
- 最近发表
- 标签列表
-
- gitpush (61)
- pythonif (68)
- location.href (57)
- tail-f (57)
- pythonifelse (59)
- deletesql (62)
- c++模板 (62)
- css3动画 (57)
- c#event (59)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- exec命令 (59)
- canvasfilltext (58)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- node教程 (59)
- console.table (62)
- c++time_t (58)
- phpcookie (58)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)