当前位置:网站首页>Time function and clock_ Differences between gettime() functions
Time function and clock_ Differences between gettime() functions
2022-06-30 12:06:00 【Look back in vain】
stay Linux We have many functions of reading time in , But some functions get absolute time When our system time changes Calculating the time difference will have an impact . Now we're going to time() and clock_gettime Function
function "clock_gettime" Is based on Linux C Time function of language , Can be used to calculate time , There are two kinds of precision, second and nanosecond .
The function prototype :
int clock_gettime(clockid_t clk_id, struct timespec *tp);
among ,cld_id Four types :
a、CLOCK_REALTIME: System real time , It changes with the real time of the system
b、CLOCK_MONOTONIC, Start timing from the moment the system starts , Not affected by the change of system time by users
c、CLOCK_PROCESS_CPUTIME_ID, This process to the current code system CPU Time spent
d、CLOCK_THREAD_CPUTIME_ID, This thread to the current code system CPU Time spent
This article uses... By default CLOCK_REALTIME, The accurate timing of parallel programs can be realized .
among ,timespec The structure includes :
struct timespec {
time_t tv_sec; /* second */
long tv_nsec; /* nanosecond */
};
and time()
First look at the function declaration , This function is contained in time.h Header file , The return value type is time_t. Is from Epoch Seconds since . If the passed in parameter is not NULL, Then the seconds will be assigned to the passed in parameters .
#include <time.h>
time_t time(time_t *timep);
// returns number of seconds since the Epoch, or -1 on error
times() function
First of all times function , The statement is as follows . You can see times The return type of the function is clock_t, And its definition is contained in the header file sys/time.h in . You can call sysconf(_SC_CLK_TCK) To get real time . Pay attention here times Functions and the above mentioned time Functions have different functions ,times Function is a way to get the process time ,time Function is a way to get the clock time .
The prototype is as follows :
clock_t times(struct tms *buf);
tms The structure is as follows :
strace tms{
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
}
notes :
tms_utime It records the time that the process executes user code .
tms_stime It records the time that the process executes the kernel code .
tms_cutime It records the time when the subprocess executes the user code .
tms_cstime It records when a child process executes kernel code
If we want to calculate Every time It needs to be used sysconf(_SC_CLK_TCK)) function , This sysconf Function can go to the information of the system . _SC_CLK_TCK Yes 1 second The number of clocks .
边栏推荐
- If it is not listed again, Kuangshi technology will not be able to endure
- [pattern recognition]
- R语言ggplot2可视化:使用ggplot2可视化散点图、aes函数中的size参数指定数据点的大小(point size)
- Getting started with the go language is simple: go handles XML files
- Lucene全文检索工具包学习笔记总结
- 自定义一个注解来获取数据库的链接
- 移除无效的括号[用数组模拟栈]
- R语言ggplot2可视化:使用ggplot2可视化散点图、aes函数中的colour参数指定不同分组的数据点使用不同的颜色显示
- led背光板的作用是什麼呢?
- 用于生成学习任务的量子神经网络2022最新综述
猜你喜欢

21、wpf之绑定使用小记

What is the function of LED backlight?

MATLAB中polarplot函数使用

Evaluation of IP location query interface Ⅲ
Redis - SDS simple dynamic string

AutoCAD - len command

nvm安装node后,在使用npm指令时候显示不是内部或外部指令

ZABBIX monitors the number of TCP connections

wallys/IPQ8074a/2x(4×4 or 8×8) 11AX MU-MIMO DUAL CONCURRENT EMBEDDEDBOARD

Redis6学习笔记-第二章-Redis6的基本操作
随机推荐
Installing onnx is very slow. Use Tsinghua image
用宝塔建第2个网站时网站总是报错:No input file specified.
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用labs函数为动画图添加动态时间标题(抽取frame_time信息)
R语言ggplot2可视化:使用ggplot2可视化散点图、aes函数中的size参数指定数据点的大小(point size)
[cf] 803 div2 A. XOR Mixup
He was the first hero of Shanghai's two major industries, but died silently in regret
Speech recognition - Fundamentals (I): introduction [speech to text]
他是上海两大产业的第一功臣,却在遗憾中默默离世
“\“id\“ contains an invalid value“
移除无效的括号[用数组模拟栈]
The sci-fi ideas in these movies have been realized by AI
R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates a dynamic scatter graph animation (GIF), and uses the labs function to add a dynamic time title to
【模式识别大作业】
Typescript readonlyarray (read only array type) details
Shutter 007 input field from zero
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and_ Set show in the point parameter_ The legend parameter is false, and the legend information is not displayed
Who still remembers "classmate Zhang"?
Openmldb meetup No.4 meeting minutes
led背光板的作用是什麼呢?
Lucene full text search toolkit learning notes summary