#include <stdio.h>#include <time.h> #define CLOCKS_PER_SEC ((clock_t)1000) int binsearch(int, int array[], int n); int main(){ int array[] = {2, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16}; int tag = 9; int res = -1; clock_t start; clock_t finish; sta…
windows: Calculates the wall-clock time used by the calling process. return:The elapsed wall-clock time since the start of the process Linux:The clock() function returns an approximation of processor time used by the program Windows: #include <stdio…
今天介绍一下clock这个函数的使用,它是C标准库的一部分,声明在头文件<time.h>中,返回处理器使用的时间值,函数声明为: clock_t clock(void); 这个函数看起来很简单,但是当使用时还是有不少需要注意的地方,让我们先看看clock_t这个类型,它表示程序所占用的处理器时间,具体的实现可以是整形或者浮点型,例如我们如果查看codeblock12.11中的time.h文件,可以看到如下定义: /* * A type for measuring processor time…
来源:http://blog.csdn.net/apull/article/details/5379819 一.获取日历时间time_t是定义在time.h中的一个类型,表示一个日历时间,也就是从1970年1月1日0时0分0秒到此时的秒数,原型是: typedef long time_t; /* time value */可以看出time_t其实是一个长整型,由于长整型能表示的数值有限,因此它能表示的最迟时间是2038年1月18日19时14分07秒. 函数time可以获取当前日历时…