2017年4月17日 星期一

linux & C/C++ 時間量測

一、time
time <exe>
選項:
-p: portable output
-o <file>: 輸出到指定檔案

範例:
time -p -o output.txt <exe>
  output:
    real 0.22
    user 0.00
    sys 0.00

read time: 實際人感受到的時間 (wall clock time)
user: 程式在user mode所花的時間
sys: 程式在kernel mode所花的時間

Ref:
http://yuanfarn.blogspot.tw/2012/08/linux-time.html

二、date
date

date 輸出目前的時間
選項:
+[FORMAT]
  其中[FORMAT]包含:
    %s: 從1970-01-01 00:00:00 UTC 到目前的秒數
    %N: nanoseconds

範例:
date +%s.%N
  output:
    1492412438.259903661 

三、gdb 內量測時間
若gdb支援python:

(gdb) python import time
(gdb) python starttime=time.time()
(gdb) c
(gdb) python print (time.time()-starttime)

若沒有則可以使用date:
(gdb) shell date +%s.%N

沒有留言:

張貼留言