![見出し画像](https://assets.st-note.com/production/uploads/images/75214052/rectangle_large_type_2_dd688df36c5264493f44e59f5c778cdf.png?width=1200)
Photo by
nanahoshi_d
Linux sortコマンドの速度 (スレッド数と速度)
Linux の標準コマンド sort のスレッド数とソート時間の関係を調査しました.
4 core, 8 threadのCPUにて,8 thread (+α)が最速で,1 thread 時の半分以下の時間でソートできました.
結果
各線のラベルは「デー多数」
![](https://assets.st-note.com/img/1648471822916-L1yM0BlX8t.png)
![](https://assets.st-note.com/img/1648471868592-Hw9MExtnGN.png)
![](https://assets.st-note.com/img/1648471894449-ZWp7Di7YGB.png)
![](https://assets.st-note.com/img/1648471992936-AQWNWaER2E.png)
![](https://assets.st-note.com/img/1648472423221-wrYb6sndDJ.png)
データ数 65536では,全ての計測値が1桁の値 (0.02秒)となってしまい解像度が非常に荒いので,掲載していません.
測定環境
ソートデータ
以下の様なテキストファイル.
各行に10桁の10進数が1個書いてある.31bit乱数.
1804289383
0846930886
1681692777
1714636915
1957747793
(以下略)
テキストデータは以下のプログラムで作成
#include <stdio.h>
#include <stdlib.h>
void main(int argc, char **argv){
int i,max=100;
if( 1<argc ){
max = atoi(argv[1]);
}
for(i=0; i<max; i++){
printf("%010d\n", rand());
}
}
ソート方法
export LC_ALL=C ; /usr/bin/time sort --parallel=1 a.txt
各スレッド数で11回ずつ実行.
PC仕様
CPU: Intel Core i7-3770 CPU @ 3.40GHz, clock rate 3.4 GHz (fixed)
HDD: Hitachi Deskstar 7K1000.C (1TB)
OS: Ubuntu 20.04.3 LTS, desktop, Linux 5.15.25
Memory: 16 GB
sort (GNU coreutils) 8.30
おまけ
スレッド数1におけるshell script
gcc ../mkdata.c
for((n=65536; n<=60000000; n*=2))
do
echo ${n}
./a.out ${n} > ../a.txt
rm -f result.${n}.txt
for i in {0..10}
do
echo ${n}.${i}
export LC_ALL=C ; /usr/bin/time sort --parallel=1 ../a.txt > /dev/null 2>> result.${n}.txt
done
done
全ディレクトリで bench.sh を実行するshell script
for dir in */.
do
cd ${dir}
bash bench.sh
cd ..
done
この記事が気に入ったらサポートをしてみませんか?