- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想知道上述常量的返回值有什么区别。
sysconf(_SC_CLK_TCK)
返回 100
CLOCKS_PER_SEC
返回 1,000,000
所以,假设我有这个:
...
start = clock();
// Process starts here
/* does something */
// Process ends here
end = clock();
double time = ((double) end-start)/CLOCK_PER_SEC; // this would return in seconds
...
如何计算进程使用的滴答数量,而不是时间?我是否使用针对 sysconf(_SC_CLK_TCK)
或 CLOCK_PER_SEC
的时间?
我正在尝试了解它们的用法。
最佳答案
根据文档,clock()
返回分辨率为 CLOCKS_PER_SEC
的时间。
其他时间函数返回分辨率为 刻 的值。 sysconf(_SC_CLK_TCK)
提供每秒滴答数。 times()
就是这样一种时间函数。
关于c - sysconf(_SC_CLK_TCK) 与 CLOCKS_PER_SEC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39712808/
如果有多个 cpu(在 mu ubuntu 14.04 桌面系统监视器显示 4 个 cpu 的“双核 I5 笔记本电脑”),sysconf(_SC_CLK_TCK) 返回 100。系统每秒有 100
我编写了一个程序来维护所有打开的文件描述符的详细信息。 因此,我使用 sysconf 函数来获取允许的运行时最大打开文件描述符。 如果数组声明不在全局中意味着它不会说任何错误。它工作正常。 这是我的程
我试图理解各种 sysconf 宏。我编写了如下程序。 int main() { fprintf(stdout, "No. of clock ticks per sec : %ld\n",sy
我试图找到UNIX计算机上每个进程的最大线程数,并编写了以下代码以使用sysconf: #include #include #include #include #include int ma
sysconf()和getrlimit()有什么联系和区别? 他们是否提供两种不同的方式来报告相同资源的限制? 我们什么时候使用哪个? 谢谢。 我发现关于这两个函数的两个相互矛盾的评论: 来自 htt
以下代码在Linux(CentOS 6.5)下编译运行 #include #include int main() { long sysval = sysconf(_SC_NPROCESSORS
我正在编译一个程序,它给出了以下错误。 gcc的版本是(GCC) 4.8.5 20150623 (Red Hat 4.8.5-4。 Utils.cpp: In static member functi
在一般情况下和跨平台支持方面,一个函数——getpagesize() 与 sysconf(_SC_PAGESIZE)——是否比另一个更可靠? 最佳答案 经过一些额外的搜索,我发现 getpagesiz
我想知道上述常量的返回值有什么区别。 sysconf(_SC_CLK_TCK) 返回 100 CLOCKS_PER_SEC 返回 1,000,000 所以,假设我有这个: ... start = cl
我正在尝试将我的程序从 Linux 移植到 Windows,但我遇到了 sysconf(_SC_CLK_TCK) 的问题。根据我的研究,Windows 中的 sysconf(_SC_CLK_TCK)
(这是 how to check if monotonic clock is supported 的后续问题) 我尝试打印 _SC_MONOTONIC_CLOCK 的值并得到 149。我试过谷歌 se
我刚刚注意到limits.h 中名为“_POSIX_*”的宏(名称上)类似于sysconf 函数的参数。例如,有一个名为“_POSIX_ARG_MAX”的宏,我也可以用“_SC_ARG_MAX”作为参
这是一个简单的演示: #include #include #include #include #include #include #include #include #include
我是一名优秀的程序员,十分优秀!