c++ 测试计算时间
2015-05-28 15:57
204 查看
/* clock example: frequency of primes */ #include <stdio.h> /* printf */ #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */ #include <math.h> /* sqrt */ int frequency_of_primes (int n) { int i,j; int freq=n-1; for (i=2; i<=n; ++i) for (j=sqrt(i);j>1;--j) if (i%j==0) {--freq; break;} return freq; } int main () { clock_t t; int f; t = clock(); printf ("Calculating...\n"); f = frequency_of_primes (99999); printf ("The number of primes lower than 100,000 is: %d\n",f); t = clock() - t; printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); return 0; } Edit & Run
<span style="font-family: monospace; white-space: pre; background-color: rgb(240, 240, 240);">Output:Calculating...The number of primes lower than 100,000 is: 9592It took me 143 clicks (0.143000 seconds).</span>
相关文章推荐
- C++计算当前时间点间隔N天的时间(不使用CTimeSpan类)
- C++测试程序执行时间代码
- C/C++中计算程序运行时间
- c/c++在windows下获取时间和计算时间差的几种方法总结
- C++ 高精度计算程序运行时间的程序
- 3.3 C++中如何计算程序运行的时间
- C/C++中计算程序运行时间
- 计算C++程序执行时间 精确到毫秒级
- C++程序运行时间计算
- C++ time(NULL) 计算持续的时间长度
- C++高精度实现计算程序运行时间
- C++ 测试时间函数
- C++中计算程序运行时间
- C++设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右下角两个点的坐标,根据坐标计算矩形的面积
- C/C++中如何计算程序运行的时间
- C++计算代码运行时间
- c++测试程序运行时间的
- c++ 计算程序运行时间
- C++中计算程序运行的时间
- C/C++中如何计算程序运行时间?