1. 程式人生 > 其它 >新學了幾招

新學了幾招

clock()在<time.h>裡,Linux和Windows下都有。clock(3) - Linux manual page (man7.org) The clock() function returns an approximation of processor time used by the program. 這個時間是程式佔用的CPU時間,不是牆上的鐘(wall clock):執行期間CPU還可能執行別的程式。CLOCKS_PER_SEC一般是1000,但可能是別的值。

ftime()在<sys/timeb.h>裡,Linux和Windows下都有。ftime(3) - Linux manual page (man7.org)

 不過NOTE: This function is no longer provided by the GNU C library.  Use clock_gettime(2) instead. This function returns the current time as seconds and milliseconds since the Epoch [紀元; 時代; 時期], 1970-01-01 00:00:00 +0000 (UTC). Coordinated Universal Time ( UTC ) replaced Greenwich Mean Time (GMT) as the World Standard for time in 1972. 此處的f是flat的意思,因為time是一個數,不是00:00:00這樣的“三維”。fopen()等的f則代表file.

rtdsc指令is used to determine how many CPU ticks took place since the processor was reset.

readlink("/proc/self/exe")能起到GetModuleFileName(NULL...)的效果。比如自己(.exe)所在路徑+"/config.txt". 現在Windows可以dir "c:\users/user",即可能不用再區分path separator

shlwapi是shell light weight api的縮寫。裡面有不區分的字串函式(在網頁裡查詢not case-sensitive). Linux下有

strncasecmp