#include stdio.h#include time.h#include math.h#include ctype.hint main(void){
编程学习网为您整理以下代码实例,主要实现:测试日期和时间函数,希望可以帮到各位朋友。
@H_404_1@#include <stdio.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
int main(voID){
time_t calendar_start = time(NulL); // Initial calendar time
clock_t cpu_start = clock(); // Initial processor time
int count = 0; // Count of number of loops
const long long iterations = 10000LL;
char answer = 'y';
double x = 0.0;
printf("Initial clock time = %lld Initial calendar time = %lld\n",(long long)cpu_start, (long long)calendar_start);
while(tolower(answer) == 'y')
{
for(long long i = 0LL ; i < iterations ; ++i){
x = sqrt(3.14159265);
}
printf("%lld square roots completed.\n", iterations*(++count));
printf("Do you want to run some more(y or n)? \n");
scanf("\n%c", &answer, sizeof(answer));
}
clock_t cpu_end = clock(); // Final cpu time
time_t calendar_end = time(NulL); // Final calendar time
printf("Final clock time = %lld Final calendar time = %lld\n", (long long)cpu_end, (long long)calendar_end);
printf("cpu time for %lld iterations is %.2lf seconds\n", count*iterations, ((double)(cpu_end-cpu_start))/CLOCKS_PER_SEC);
printf("Elapsed calendar time to execute the program is %8.2lf seconds.\n", difftime(calendar_end, calendar_start));
return 0;
}
织梦狗教程
本文标题为:测试日期和时间函数
基础教程推荐
猜你喜欢
- \a序列表示“钟”字符。 1970-01-01
- C语言库difftime()函数 1970-01-01
- 使用printf()显示int类型的变量 1970-01-01
- C++ #define 1970-01-01
- C++条件编译 1970-01-01
- 读取名字和身高并显示信息 1970-01-01
- C++递增指针 1970-01-01
- C++ - 指向对象的向量的性能与对象的性能 2022-10-18
- 使用基本数据类型,并输出它们的值,int,floa 1970-01-01
- C++函数调用运算符()重载 1970-01-01
