C++ で clock_t 関数を使用してテストしていますが、問題が発生しました。コンパイルするときは、2 つの異なるコンパイラで行います。私の Windows 7 コンピューター (2012) の Visual Studio、および「レンジャー」と呼ばれる Unix システムの g++。さまざまな並べ替え関数を実行するのにかかる時間を秒単位 (最大 1000 分の 1 秒) で出力するためにコードをコンパイルしたところ、g++ コンパイラはタイムスタンプを 1000 で除算する試みを完全に無視しているようですミリ秒から 2 番目の形式に変換します。何かアドバイス?これに関して、g++ と Visual Studio のコンパイラに違いはありますか?
短いコード スニペット (出力と除算のために行うこと):
//Select Sort
begin = clock(); //Begin time
selectionSort(array, n);
end = clock(); //End time
d_select = ((float)(end/1000.0) - (float)(begin/1000.0)); //Calculates the time in MS, and converts from MS, to a float second.
//Output data
cout << setprecision(3) << fixed; //Set precision to 3 decimal places, with a fixed output (0's are displayed regardless of rounding)
cout << n << "\t" << d_bubble << "\t" << d_insert << "\t" << d_merge << "\t" << d_quick << "\t"
<< d_select << endl;
Visual Studio の出力 (正しい):
n Bubble Insert Merge Quick Select
100000 12.530 1.320 0.000 0.030 2.900
Unix の出力 (正しくない) :
n Bubble Insert Merge Quick Select
100000 51600.000 11700.000 30.000 150.000 18170.000
助言がありますか?ありがとう!