利用gettimeofday简单测试程序用时
来源:互联网 发布:量子计算机人工智能股 编辑:程序博客网 时间:2024/06/05 03:39
centos$ man 2 gettimeofday
#include <sys/time.h>int gettimeofday(struct timeval *tv, struct timezone *tz);struct timeval { time_t tv_sec; // seconds suseconds_t tv_usec; //microseconds};// it gives the number of seconds and microseconds since the Epoch (see time(2))struct timezone { int tz_minuteswest; //minutes west of Greenwich int tz_dsttime; //type of DST correction};// if tv or tz is NULL, the corresponding structure is no set or returned.
简单测试用例
程序中添加两个struct timeval 来记录开始和完成的时间就可以了。
#include <stdio.h>#include <stdlib.h>#include <sys/time.h>int main(){ struct timeval beginTime, endTime; if (gettimeofday(&beginTime, NULL) == -1) return -1; for (int i = 1; i <= 10000; i++) for (int j = 1; j <= 10000; j++) ; if (gettimeofday(&endTime, NULL) == -1) return -1; double seconds; seconds = 1000000*(endTime.tv_sec - beginTime.tv_sec) + (endTime.tv_usec - beginTime.tv_usec); seconds /= 1000000; printf("using time : %f\n", seconds); return 0;}
运行结果
0 0
- 利用gettimeofday简单测试程序用时
- time函数的使用-测试程序用时
- 利用Eclipse+Tomcat开发Web程序(简单例子测试)
- java计算程序用时
- 程序用时记录函数
- C# 计算程序用时
- gettimeofday()
- gettimeofday
- gettimeofday
- gettimeofday()
- gettimeofday
- gettimeofday
- gettimeofday
- gettimeofday
- gettimeofday
- 简单的测试程序
- C语言 利用gettimeofday()时间差计算
- 简单SQL语句执行用时
- 重复数据删除:基于相同数据的检测
- vi/vim多行注释和取消注释(转载)
- fft
- TI DSP TMS320C66x学习笔记之内联指令(c6x.h中文注释)(六)
- 【15】时间、日期和日历
- 利用gettimeofday简单测试程序用时
- SQL开发整理
- 安卓项目中的R.java文件丢失如何解决
- 【CSS3】变形--缩放 scale()
- openwrt install ipk 的步骤
- android ndk编写
- SQLITE在ANDROID上的一个BUG
- 欢迎使用CSDN-markdown编辑器
- 关于递归简单理解