UNIX 时间命令 - 输入时间是否被考虑在内?

发布于 2024-10-06 14:20:28 字数 219 浏览 0 评论 0原文

我正在使用 unix time 命令来记录运行 java 程序的时间。

我的程序开始运行时所做的第一件事是要求用户输入文件路径。

输入此命令并按回车键所花费的时间是否已计入此命令返回的任何时间统计信息中? 我的 time 命令的输出格式为:

.#u #.#s #:#.# #.#% ##+#k ##+#io #pf+#w

其中 # 是一个整数

谢谢

I'm using the unix time command to record times for running a java program.

The first thing my program does when it begins running is ask the user to input a file path.

Is the time taken to type this in and hit return factored into any of the time statistics that this command returns?
The output for my time command is of the form:

.#u #.#s #:#.# #.#% #+#k #+#io #pf+#w

where # is an integer

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2024-10-13 14:20:28

是的,提供输入所花费的时间是实时的一部分(输出中的第三个条目)。

简单演示:

$ time(sleep 5 ; echo hi | read)

real      0m5.005s
user      0m0.000s
sys       0m0.004s

这里 echo hi 将在 std 输出上打印 hi,而 read 将读取它。在进行写入和读取之前,我添加了 5 秒的延迟。我已经为整个事情计时了。

如图所示,实时时间约为 5 秒,这意味着它考虑了 read 命令读取输入所花费的时间。

为了完整起见,用户时间是 CPU 运行程序中的指令(例如循环、条件语句)所花费的时间。

而sys time是CPU执行系统调用所花费的时间。在我们的示例中,我们看到 4 毫秒的系统时间,因为该命令涉及许多系统调用,例如 readwrite 等。

Yes, the time taken to provide input is a part of the real time (3rd entry in your output).

Simple demo:

$ time(sleep 5 ; echo hi | read)

real      0m5.005s
user      0m0.000s
sys       0m0.004s

Here the echo hi will print hi on std output and read will read it. I've added a 5 sec delay before this writing and reading happens. And I've timed the entire thing.

As seen the real time is around 5 sec, which means it takes into account the time the read command took to read the input.

Just to be complete the user time is the time the CPU takes to run the instructions in our program like the loops, the conditionals.

And the sys time is the time taken by the CPU to perform system calls. In our example we see a 4 msec of sys time because there are many sys calls involved in that command like read, write etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文