2015年11月24日 星期二

fopen, access and stat 執行效能的比較

fopen, access, and stat是常用來檢查檔案是否存在的c library

本篇文章就執行效能來做一個比較

檔案存在

fopenaccessstat
time
Tue Nov 24 13:36:27 2015
Tue Nov 24 13:36:45 2015
Total time: 18s
Tue Nov 24 13:36:45 2015
Tue Nov 24 13:36:52 2015
Total time: 7s
Tue Nov 24 13:36:52 2015
Tue Nov 24 13:36:59 2015
Total time: 7s

檔案不存在

fopenaccessstat
timeTue Nov 24 13:38:21 2015
Tue Nov 24 13:38:34 2015
Total time: 13s
Tue Nov 24 13:38:34 2015
Tue Nov 24 13:38:41 2015
Total time: 7s
Tue Nov 24 13:38:41 2015
Tue Nov 24 13:38:48 2015
Total time: 7s

結果:
stat跟access不相上下
stat, access都比fopen快

source code download:
https://github.com/nelsonchung/nelson_sample_code_for_c/blob/master/diff_fopen_access_stat.c

透過Facebook分享