当前位置:网站首页>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
边栏推荐
- FPGA interview topic notes (I) - FPGA development process, metastable state and competitive risk, build and hold time, asynchronous FIFO depth, etc
- Chapter 4 of machine learning [series] naive Bayesian model
- ijkPlayer中的错误码
- Use of constructors
- Sqli-libs post injection question 11-17 actual combat
- Notes sur les questions d'entrevue de la FPGA (IV) - - détecteur de séquence, Code gris dans le domaine de l'horloge croisée, opération de ping - pong, réduction de la perte statique et dynamique, err
- 538.把二叉搜索树转换成累加树
- FPGA面试题目笔记(一)——FPGA开发流程、亚稳态和竞争冒险、建立保持时间、异步FIFO深度等
- Vulnhub's breach1.0 range exercise
- Shandong University machine learning experiment VI k-means
猜你喜欢
![Chapter 1 of machine learning [series] linear regression model](/img/e2/1f092d409cb57130125b0d59c8fd27.jpg)
Chapter 1 of machine learning [series] linear regression model

Who is stronger, zip or 7-Zip, and how to choose?

Graphsage paper reading

Sqli-libs range 23-24 filtration and secondary injection practice

FPGA设计——乒乓操作实现与modelsim仿真

Matlab实现均值滤波与FPGA进行对比,并采用modelsim波形仿真

Solve the problem that ffmpeg obtains aac audio files with incorrect duration

Why is it that the live video of the devices connected to easygbs suddenly cannot be played? Insufficient database read / write

The classification effect of converting video classification data set to picture classification data set on vgg16

Deployment of Flink
随机推荐
关于SIoU的原理和代码实现(回顾IoU、GIoU、DIoU、CIoU)
022-Redis数据库0基础入门
Topic collection of FIFO minimum depth calculation
MongoDB安装
Jenkins voucher management
学好C语言从关键字开始
This point of arrow function
Multimedia框架解析之MediaExtractor源码分析(一)
Installing and using sublist3r in Kali
break,continue有什么区别和用法?
Why don't we have our own programming language?
箭头函数的this指向
FPGA面試題目筆記(四)—— 序列檢測器、跨時鐘域中的格雷碼、乒乓操作、降低靜動態損耗、定點化無損誤差、恢複時間和移除時間
Simple understanding of XML and JSON
[]==![]
EasyGBS接入的设备视频直播突然全部无法播放是为什么?数据库读写不够
Chapter 2 of machine learning [series] logistic regression model
Observer mode (listener mode) + thread pool to realize asynchronous message sending
Handwritten promise [01] - Implementation of promise class core logic
FMT package usage of go and string formatting