当前位置:网站首页>Count the time-consuming duration of an operation (function)
Count the time-consuming duration of an operation (function)
2022-06-11 06:23:00 【Tinghua_ M】
C Medium statistics time
stay C Functions can be used in languages gettimeofday() Function to get the time . Its precision can be as subtle as . Let's look at it first man Description in the manual :
$ man gettimeofday
DESCRIPTION
The functions gettimeofday() and settimeofday() can get and set the time as well as a timezone.
The tv argument is a struct timeval (as specified in <sys/time.h>):
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
This means that the function returns timeval Time value of type ,tv_sec Is the second ,tv_usec It represents microseconds .
give an example
#include <stdio.h>
#include "api.h"
#include <time.h>
#include <sys/time.h>
int main(int argc, char * argv[])
{
struct timeval tpstart,tpend;
gettimeofday(&tpstart,NULL);
seek("/sdcard/Music/mm.mp3", 0, 3600);
gettimeofday(&tpend,NULL);
printf("Used Time:%f\n",tpend.tv_usec - tpstart.tv_usec);
return 0;
}
This example is to debug a self defined seek function , You can also replace it with the function you want to debug , Two are defined timeval The variable of tpstart,tpend, Record the time when the function starts and ends , Subtract the two , You can calculate the time consumption of this function . What I'm printing here is tv_usec( Microsecond ), You can also print according to your own needs tv_sec.
explain :
In the use of gettimeofday() Function time , The second parameter is generally empty , Because we usually just want to get the current time , Without getting timezone The numerical
边栏推荐
- How to treat the ethical issues arising from driverless Technology
- A collection of problems on improving working frequency and reducing power consumption in FPGA design
- Human gene editing technology and ethical issues behind it [personal view, for reference only]
- This point of arrow function
- Simple knapsack problem
- QT socket设置连接超时时间
- Global case | how Capgemini connects global product teams through JIRA software and confluence
- Ethical discussion on reptile Technology
- 100. 相同的树
- CCS安装编译器的方法
猜你喜欢

Analyze the principle of configuration center from the perspective of Nacos client

Global case | how Capgemini connects global product teams through JIRA software and confluence

CCS安装编译器的方法

jenkins-用户权限管理

FPGA interview notes (IV) -- sequence detector, gray code in cross clock domain, ping-pong operation, static and dynamic loss reduction, fixed-point lossless error, recovery time and removal time

autojs,读取一行删除一行,停止自己外的脚本

Communication between different VLANs

Convert text label of dataset to digital label

Detailed steps for installing mysql-5.6.16 64 bit green version

563. 二叉树的坡度
随机推荐
Warning: Each child in a list should have a unique “key“ prop.
Analyze the principle of configuration center from the perspective of Nacos client
What is a planning BOM?
Wechat applet (authorized login) (not recommended, click the home page to view the updated authorized login)
通过两种方式手写一个消息队列
Convert text label of dataset to digital label
MATLAB realizes mean filtering and FPGA for comparison, and uses Modelsim waveform simulation
Differences between FindIndex and indexof
FPGA interview topic notes (I) - FPGA development process, metastable state and competitive risk, build and hold time, asynchronous FIFO depth, etc
QT socket设置连接超时时间
Compliance management 101: processes, planning and challenges
Sharing of personal common software and browser plug-ins
Who is stronger, zip or 7-Zip, and how to choose?
个人常用软件及浏览器插件分享
fatal: refusing to merge unrelated histories
verilog实现双目摄像头图像数据采集并modelsim仿真,最终matlab进行图像显示
Docker安装Mysql、Redis
Jenkins user rights management
Servlet
SQLI_ LIBS range construction and 1-10get injection practice