C语言的两个工具函数
来源:互联网 发布:安装ubuntu服务器版 编辑:程序博客网 时间:2024/05/01 07:29
1. 测试程序执行时间的函数
#include <stdio.h>#include <stdlib.h>#include <time.h>void sleep( clock_t wait );void main( void ){ long i = 60000000L;//6000 W clock_t start, finish; double duration; /* Delay for a specified time. */ printf( "Delay for three seconds\n" ); sleep( (clock_t)3 * CLOCKS_PER_SEC ); printf( "Done!\n" ); /* Measure the duration of an event. */ printf( "Time to do %ld empty loops is ", i ); start = clock(); while( i-- ) ; finish = clock(); duration = (double)(finish - start) / CLOCKS_PER_SEC; printf( "%2.2f seconds\n", duration );}/* Pauses for a specified number of milliseconds. */void sleep( clock_t wait ){ clock_t goal; goal = wait + clock(); while( goal > clock() ) ;}
2. 用于随机生成数组并存入文件,以便多个函数调用
#include <stdio.h>#include <stdlib.h>#include <time.h>#define DATASIZE 10000int main(int argc, char ** argv){ const char * file_name = "out.dat"; FILE * fp = fopen(file_name, "wb");//必须放在其他变量的定义之前 int i, a, b[DATASIZE]; srand( time(NULL) ); for(i=0; i<DATASIZE; i++) { a=rand()%100; fwrite(&a, sizeof(int), 1, fp); } fclose(fp); fp = fopen(file_name, "rb"); fread(&b, sizeof(int), DATASIZE, fp); for(i=0; i<10; i++) printf("%d ", b[i]); printf("\n"); return 0;}
end
- C语言的两个工具函数
- 两个c语言的调用函数总结
- c语言--交换两个数的函数
- c语言关于时间的两个函数
- c语言工具函数
- c语言 main函数的两个参数的含义
- C语言两个时间段是否交叉的判断函数
- C语言变参函数的两个实现
- C语言中异常处理的两个函数
- C语言——字符串查找字符的两个函数
- c语言中用函数传递数组的两个方法
- C语言 两个分数的四则运算,用函数调用实现
- C语言关于localtime_s()和asctime_s()两个函数的用法。
- C语言 使用函数实现两个数的交换
- C语言-使用函数实现两个数的交换
- 【C语言】自定义连接两个字符串函数
- 两个简单的C函数
- C语言的函数
- 16. 43. 1. 鼠标拽拖-黑客帝国-画皮Mouse drag and draw
- Zend Studio 5.5 中文显示及字体选择
- 将TIzigbee开源协议栈中的OS操作系统移植出来,放在STC12C60S2中使用
- addpath matlab
- linux开机logo制作
- C语言的两个工具函数
- 归一化RGB图像
- 企鹅快跑——腾讯敏捷历程揭秘
- 算法导论 逆序对问题
- uboot 移植之gd_t,bd_t
- iostream
- 请问Eclipse中源码的中文部分都显示成乱码如何解决 .
- get out & clean
- 微博上对乔布斯的评价