fseek讀,到底有多快!

2021-04-15 02:50:26 字數 4627 閱讀 2401

常聽人說,fseek很快!到底多快?如果不知道多快,就乙個勁的爭論很快!好像不必擔心的快一樣。這種常識性的東西不知道,妄談系統設計,就會出笑話的。下面做個實驗,測測fseek的量級。

測試的方法:

1. 乙個檔案512m

2. 乙個執行緒對應乙個檔案,然後在這個檔案裡邊進行rand fseek,然後讀1k位元組

1. 機器配置

硬碟:型別:希捷 酷魚7200.9/st3160812as

容量:160g

轉速:7200rpm

快取容量:8m

20080201104250 nt 5171.3075500976 thread:1,time:33211

20080201104250 nt 5171.3085990832 thread:0,time:33480

20080201104250 nt 5171.3085993664 complete to seek!

20080201105502 nt 5312.3076189104 thread:1,seeknum:1000,time:27757

20080201105517 nt 5312.3086678960 thread:0,seeknum:1000,time:42990

20080201105518 nt 5312.3065699248 thread:2,seeknum:1000,time:43848

20080201105518 nt 5312.3044719536 thread:4,seeknum:1000,time:43936

20080201105518 nt 5312.3055209392 thread:3,seeknum:1000,time:43956

20080201105518 nt 5312.3086681792 complete to seek!

20080201105557 nt 5320.2991479728 thread:9,seeknum:1000,time:6

20080201105632 nt 5320.3075398576 thread:1,seeknum:1000,time:34968

20080201105632 nt 5320.3085888432 thread:0,seeknum:1000,time:35699

20080201105648 nt 5320.3064908720 thread:2,seeknum:1000,time:51508

20080201105649 nt 5320.3033439152 thread:5,seeknum:1000,time:52242

20080201105650 nt 5320.3054418864 thread:3,seeknum:1000,time:52789

20080201105654 nt 5320.3001969584 thread:8,seeknum:1000,time:57389

20080201105657 nt 5320.3043929008 thread:4,seeknum:1000,time:60030

20080201105659 nt 5320.3022949296 thread:6,seeknum:1000,time:61854

20080201105659 nt 5320.3012459440 thread:7,seeknum:1000,time:61960

20080201105659 nt 5320.3085891264 complete to seek!

20080201105902 nt 5363.3076279216 thread:1,seeknum:100,time:1736

20080201105902 nt 5363.3086769072 thread:0,seeknum:100,time:1749

20080201105902 nt 5363.3086771904 complete to seek!

結論:每秒100多次的頻率

2. 希捷 st3146845lc(scsi/15000轉/3.5)   硬碟容量 146gb   

20080201111345 nt 11512.3086085040 thread:0,seeknum:1000,time:6322

20080201111345 nt 11512.3075595184 thread:1,seeknum:1000,time:6592

20080201111345 nt 11512.3086087872 complete to seek!

20080201111436 nt 11516.3065846704 thread:2,seeknum:1000,time:1516

20080201111439 nt 11516.3086826416 thread:0,seeknum:1000,time:4843

20080201111440 nt 11516.3076336560 thread:1,seeknum:1000,time:4984

20080201111440 nt 11516.3086829248 complete to seek!

20080201111014 nt 11394.2991508400 thread:9,seeknum:1000,time:7

20080201111019 nt 11394.3001998256 thread:8,seeknum:1000,time:5910

20080201111021 nt 11394.3064961968 thread:2,seeknum:1000,time:7713

20080201111023 nt 11394.3054472112 thread:3,seeknum:1000,time:9722

20080201111024 nt 11394.3012488112 thread:7,seeknum:1000,time:10040

20080201111025 nt 11394.3033492400 thread:5,seeknum:1000,time:11918

20080201111025 nt 11394.3023002544 thread:6,seeknum:1000,time:11929

20080201111026 nt 11394.3043982256 thread:4,seeknum:1000,time:12528

20080201111027 nt 11394.3075455920 thread:1,seeknum:1000,time:13119

20080201111027 nt 11394.3085945776 thread:0,seeknum:1000,time:13574

20080201111027 nt 11394.3085948608 complete to seek!

20080201113340 nt 11671.2956921776 thread:12,seeknum:1000,time:11054

20080201113340 nt 11671.2967411632 thread:11,seeknum:1000,time:11718

20080201113341 nt 11671.2977901488 thread:10,seeknum:1000,time:12378

20080201113341 nt 11671.2946431920 thread:13,seeknum:1000,time:12555

20080201113343 nt 11671.2935942064 thread:14,seeknum:1000,time:14755

20080201113345 nt 11671.3065510832 thread:2,seeknum:1000,time:16908

20080201113346 nt 11671.3053452208 thread:3,seeknum:1000,time:17139

20080201113346 nt 11671.2988391344 thread:9,seeknum:1000,time:17249

20080201113346 nt 11671.3042962352 thread:4,seeknum:1000,time:17454

20080201113346 nt 11671.3076000688 thread:1,seeknum:1000,time:17648

20080201113347 nt 11671.3086490544 thread:0,seeknum:1000,time:18470

20080201113347 nt 11671.2998885296 thread:8,seeknum:1000,time:18917

20080201113348 nt 11671.3021982640 thread:6,seeknum:1000,time:19228

20080201113348 nt 11671.3009379248 thread:7,seeknum:1000,time:19555

20080201113348 nt 11671.3032472496 thread:5,seeknum:1000,time:19576

20080201113348 nt 11671.3086493376 complete to seek!

每秒不到1000次。

也就是說:如果要是seek讀,每次讀1k,只有1m/秒。

(這個結論只供參考)

也可以把這個實驗擴充套件,

比如:如果必須seek,那麼讀多少資料才是最經濟的?

這些經常用到的效能引數是非常有用的。那往往都是乙個系統的瓶頸所在。     

fseek與rewind到底有何區別

當我們要設定檔案位置為給定流 stream 的檔案的開頭時,其實我們有兩種選擇,直接呼叫rewind函式,rewind fp 或者使用fseek fseek fp,0l,seek set 那麼這兩者有什麼區別呢?我們從介面本身的使用和實現兩個反面來說。首先,從介面本身來說,rewind是沒有返回值的...

記憶體資料庫到底有多快

併發量太高的應用中 比如10分鐘內插入300w條記錄 資料庫往往難堪重負,在沒有銀子實現伺服器集群 負載均衡 分布式儲存的情況下,可以嘗試一下把資料庫做乙個臨時副本全部放在記憶體中處理,完成操作後,再同步到硬碟的物理資料庫中。那麼,把資料庫放在記憶體中到底有多快?晚上抽空試了一下 步驟1 先用ram...

到底有多二

7 3 到底有多二 15 分 乙個整數 犯二的程度 定義為該數字中包含2的個數與其位數的比值。如果這個數是負數,則程度增加0.5倍 如果還是個偶數,則再增加1倍。例如數字 13142223336是個11位數,其中有3個2,並且是負數,也是偶數,則它的犯二程度計算為 3 11 1.5 2 100 約為...