- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目前,我正在尝试对一个过程进行计时,以与我在网上找到的使用 opencl 的示例程序进行比较。然而,当我尝试计算此过程的时间时,我会得到非常奇怪的值,如下所示。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <CL/cl.h>
#include <time.h>
int main(void) {
int n = 100000;
size_t bytes = n * sizeof(double);
double *h_a;
double *h_b;
double *h_c;
h_a = (double*)malloc(bytes);
h_b = (double*)malloc(bytes);
h_c = (double*)malloc(bytes);
int i;
for(i = 0; i < n; i++)
{
h_a[i] = sinf(i)*sinf(i);
h_b[i] = cosf(i)*cosf(i);
}
clock_t start = clock();
for(i = 0; i < n; i++)
h_c[i] = h_a[i] + h_b[i];
clock_t stop = clock();
double time = (stop - start) / CLOCKS_PER_SEC;
printf("Clocks per Second: %E\n", CLOCKS_PER_SEC);
printf("Clocks Taken: %E\n", stop - start);
printf("Time Taken: %E\n", time);
free(h_a);
free(h_b);
free(h_c);
system("PAUSE");
return 0;
}
结果:
C:\MinGW\Work>systesttime
Clocks per Second: 1.788208E-307
Clocks Taken: 1.788208E-307
Time Taken: 0.000000E+000
Press any key to continue . . .
它为那里的一切赋予了非常奇怪的值(value)。我知道它必须在 1,000,000 左右,但我不知道为什么这样做。它曾经为同样令人担忧的所有事物给出大约 6E+256 的值。
最佳答案
看起来您的clock_t
不是 double 的,因此%E
是错误的格式说明符。
可能很长
。试试这个:
printf("Clocks per Second: %E\n", (double)CLOCKS_PER_SEC);
关于c - 使用 time.h 的奇怪 CLOCKS_PER_SEC 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41870739/
我们正在运行一些基准测试,我们注意到 function foo这叫function bar并等待响应比 function bar 花费的时间更少 . Foo 驻留在客户端上,它是一个独立的物理机器,而
我使用 AMD FX 4300 和 3.8GHz,这意味着每秒 3.8G 时钟。但是当我运行命令 CLOCKS_PER_SEC 时,它显示了其他内容。 #include #include i
CLOCKS_PER_SEC 通常表示为什么数据类型? long unsigned int? 时钟时间?它是否因实现而异? 我问是因为我在返回值中使用了 CLOCKS_PER_SEC,我想确保我使用了
这是我程序的一部分; double get_cpu_time(){ return (double)clock() / CLOCKS_PER_SEC; 但是我得到以下错误; In function ‘
在阅读 The C Programming Language 2e 中的一些页面时,我发现了这一点。 clock_t clock(void) : clock returns the processor
我正在运行一个 cpp 代码,但我注意到一件事,在 Windows 7 上,C++ 代码中的 CLOCKS_PER_SEC 给出了 1000,而在 linux fedora 16 上它给出了 1000
我正在尝试使用 asm 和 rdtsc 实现我自己的 clock() 版本。但是我很不确定它的返回值。是循环吗?奥德是微秒吗? 我也对 CLOCKS_PER_SEC 感到困惑。这怎么可能是恒定的? 是
我试图通过调用我在 Display() 回调函数开始时创建的自定义 CalculateFrameRate 方法来计算 GLUT 窗口的帧率。我在执行每一帧的计算后调用 glutPostRedispla
我刚刚编写了这个简短的 C++ 程序来估计每秒的实际时钟滴答数。 #include #include using namespace std; int main () { for(int
我在 C++ 中有此代码片段,但很难将其转换为 C# clock_t now = clock(); myStartTime = start; myTimeLimit = 5 // in seconds
我想在我的程序中使用定时器功能。按照 How to use clock() in C++ 中的示例,我的代码是: int main() { std::clock_t start = std::
我想知道上述常量的返回值有什么区别。 sysconf(_SC_CLK_TCK) 返回 100 CLOCKS_PER_SEC 返回 1,000,000 所以,假设我有这个: ... start = cl
我正在使用以下短程序来测试 std::clock(): #include #include int main() { std::clock_t Begin = std::clock()
我不知道这是一个错误还是我是唯一一个面临这个问题的人, 在 Eclipse CDT indigo 中,创建一个新的 C++ 可执行项目并在 C++ 源文件夹中创建一个 CPP 文件。即源代码/测试.c
我正在将我的旧代码库移植到 VS 2015。代码是: #if XYZ .... #elif CLOCKS_PER_SEC > 999 //<< Getting error here. ...
大家好,我是一名初学者 C 程序员,当我编写一个简单的终端 watch 时,我注意到我的代码的执行顺序有问题:我运行程序时不显示时间,首先光标闪烁约 3 秒钟,然后显示时间。这是我的代码: #incl
这个问题已经有答案了: What’s the correct way to use printf to print a clock_t? (5 个回答) 已关闭 6 年前。 目前,我正在尝试对一个过程
我正在尝试按照 official guide 编译 NFIQ 2.0 源代码.在最后的构建步骤中,出现以下错误。 FRFXLLCreateLibraryContext.cpp:72:5: error:
Windows 10 中的 GNU C++ 编译器返回 CLOCKS_PER_SEC = 1000,但我需要测量低于毫秒间隔的算法的编译时间(这是一个学校项目)。有没有办法将 CLOCKS_PER_S
我对准确计时 C++ 应用程序很感兴趣。 “时间”似乎有多种定义,但为了这个问题......我对我在现实世界中指望 watch 的时间感兴趣......如果这有任何意义!无论如何,在我的应用程序中,我
我是一名优秀的程序员,十分优秀!