Linux 的好用指令:time

Well ... 寫程式常常要寫一個功能,那就是程式執行了多久。過去的作法往往是寫在程式內部,雖然不困難但是很煩。今天聽到一隻 Linux 的指令可以輕鬆達成我要的功能:time。不是新東西,只能說是自己孤陋寡聞。

用法如下:

$ time ./multicoretest parallel 4
Creating thread 0
Creating thread 1
Creating thread 2
Thread 1 started
Thread 0 started
Task 0 started
Thread 2 started
Task 2 started
Creating thread 3
Task 1 started
Main completed
Thread 3 started
Task 3 started
Task 0 completed with result 2.996422e+06
Thread 0 done
Task 3 completed with result 2.996422e+06
Thread 3 done
Task 1 completed with result 2.996422e+06
Thread 1 done
Task 2 completed with result 2.996422e+06
Thread 2 done

real    0m1.806s
user   0m6.444s
sys    0m0.000s



real time 表示後面所接的指令或程式從開始執行到結束時間。user time 表示程式在 user mode 所佔用的 CPU 時間總和。system time 表示程式在 kernel mode 所佔用的 CPU 時間總和。



ㄟ...real 比 user 還要大ㄟ?這是因為這個範例有開 thread,而我的電腦是4個核心的緣故。

留言

這個網誌中的熱門文章

我弟家的新居感恩禮拜分享:善頌善禱

Openssl 範例程式:建立SSL連線

如何利用 Wireshark 來監聽 IEEE 802.11 的管理封包