当前位置: 动力学知识库 > 问答 > 编程问答 >

c - Recording time of a program

问题描述:

So I'm working on a c assignment that generates an array, and uses threads to determine different characteristics.

At the end of the program I need to print the wall time, the user time, and the system time. I thought I did this correctly but my results seem to point otherwise.

After multiple tests, The user time is almost always 0 and the system time is always 0. I know the user time should be greater than the wall time since it's multithreaded code.

Here's how I'm calculating it, if anyone could point out my mistake or explain why its getting an incorrect time then that'd be great:

EDIT: issue was irrelevant with code. (something else was wrong in my threads)

thanks

网友答案:

System time should almost definitely be zero, I wouldn't expect much time to be spent in kernel-mode. As for User Time being zero, it is possible that all operations are taking less than one CPU tick. If you are trying to time a short lived operation (for example, one call to malloc or something), then I would definitely expect the time to be zero.

分享给朋友:
您可能感兴趣的文章:
随机阅读: