c语言中如何添加计时函数,统计程序执行的时间
2016-12-09 16:55
288 查看
这里举一个例子,行优先和列优先遍历二维数组的程序执行时间比较,这里需要调用 time.h
编译环境为vs2013
编译环境为vs2013
#include <stdio.h> #include <stdlib.h> #include <time.h> #define M 10000000 #define N 10 short a[M] ; void assign_array_rows() { int i, j; for (i = 0; i<M; i++) for (j = 0; j<N; j++) a[i][j] = 0; } void assign_array_cols() { int i, j; for (j = 0; j<N; j++) for (i = 0; i<M; i++) a[i][j] = 0; } int main() { clock_t start, finish; double duration; start = clock(); assign_array_rows(); finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf("行优先用时: %f seconds\n", duration); start = clock(); assign_array_cols(); finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf("列优先用时: %f seconds\n", duration); system("pause"); return 0; }
相关文章推荐
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- c语言中如何添加计时函数,统计程序执行的时间
- Linux 精准计时-暨计算程序或函数执行的时间
- Linux 精准计时-暨计算程序或函数执行的时间
- linux下的时间相关函数以及如何统计程序运行时间
- C#时间函数(程序运行计时,页面运行计时)
- C# 时间函数(几个常用时间,程序运行计时,页面运行计时)
- Windows下利用C语言获得函数的执行时间
- C# 定时器事件。(设置时间间隔,间歇性执行某一函数,控制台程序)
- Linux下的函数执行时间的统计方法
- php set_time_limit(0) 设置程序执行时间的函数
- C语言中如何在main函数开始前执行函数
- 如何统计代码行执行的时间?
- 如何在sqlplus中查看oracle数据库sql语句执行计划,执行时间和统计信息