Здравствуйте, AlexGin, Вы писали:
O>>Мне вот тоже интересно, кто же быстрее (и в каких случаях) — MS C/C++ Compiler или MinGW.
AG>Мои тесты производительности, разработанные окло года назад (вычисления по int числам, double числам и тригонометрия) — здесь:
AG>Результаты прогонов теста на моём рабочем компе приведены ниже — очевидно, что чем быстрее, тем лучше
AG>MinGW 5.3.0 (32bit):
AG>Int числа => 5 sec;
AG>Double => 5 sec;
AG>Trigonometry => 6 sec;
AG>MSVC 2015 (32bit):
AG>Int числа => 2 sec;
AG>Double => 2 sec;
AG>Trigonometry => 4 sec;
AG>P.S. Все исходные коды моего тестового приложения — на GitHub-е
AG>https://github.com/AlexGin/Math.git
AG>если есть желание скачиваем и тестируем
Убрал гуёвые вызовы, состряпал консольное приложение.
Собрал тремя студиями — 2008, 2013 и 2017RC.
У меня результаты получились не столь оптимистичные.
N_MULTIPLY пришлось уменьшить на два порядка (=100000).
VS2008, x386
Trigonometry: 82.408348 msec
Double: 31.626005 msec
Int числа: 39.800537 msec
VS2008, x64
Trigonometry: 92.026453 msec
Double: 34.001156 msec
Int числа: 36.169715 msec
VS2013, x386
Trigonometry: 2568.560003 msec
Double: 18.488439 msec
Int числа: 24.076877 msec
VS2013, x64
Trigonometry: 979.826838 msec
Double: 18.001274 msec
Int числа: 23.740496 msec
VS2017RC, x386
Trigonometry: 2536.576880 msec
Double: 17.856891 msec
Int числа: 23.914318 msec
VS2017RC, x64
Trigonometry: 2538.357091 msec
Double: 18.106746 msec
Int числа: 24.057165 msec
AG>P.P.S. Теперь ясно, почему же среда разработки Qt Creator для Windows попадает к нам откомпилированной (авторами из независимой Qt Company), именно на таком "ненавистном" MSVC...
| | сорец |
| |
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <math.h>
#include <time.h>
// ==========================================================================
// Stop watch class.
class CStopWatch
{
public:
// Constructor.
CStopWatch()
{
// Ticks per second.
QueryPerformanceFrequency( &liPerfFreq );
}
// Start counter.
void Start()
{
liStart.QuadPart = 0;
QueryPerformanceCounter( &liStart );
}
// Stop counter.
void Stop()
{
liEnd.QuadPart = 0;
QueryPerformanceCounter( &liEnd );
}
// Get duration.
long double GetDuration()
{
return ( (liEnd.QuadPart - liStart.QuadPart) / long double(liPerfFreq.QuadPart) ) * 1000; //return result in milliseconds
}
private:
LARGE_INTEGER liStart;
LARGE_INTEGER liEnd;
LARGE_INTEGER liPerfFreq;
};
// ==========================================================================
int N_MULTIPLY = 100000;// 00;
const int N_GENERATED = 1000;
int randoms[N_GENERATED];
int outputs[N_GENERATED];
double randDbl[N_GENERATED];
double outpDbl[N_GENERATED];
static void generate_randoms()
{
CStopWatch watch;
watch.Start();
for( int i = 0; i < N_GENERATED; i++ )
randoms[i] = rand();
watch.Stop();
long double dur = watch.GetDuration();
printf("Generating int randoms took %lf msec\n", dur);
}
static void nativeCompute()
{
CStopWatch watch;
watch.Start();
int result = 0;
for(int i = 2; i < N_MULTIPLY; i++)
{
for( int j = 0; j < N_GENERATED; j++ )
{
result = randoms[j] * i;
result++;
outputs[j] = result;
}
}
watch.Stop();
long double dur = watch.GetDuration();
printf( "Native took %lf msec\n", dur );
}
static void generate_dbl_randoms()
{
CStopWatch watch;
watch.Start();
for (int i = 0; i < N_GENERATED; i++)
randDbl[i] = double(1.11 * (double)rand());
watch.Stop();
long double dur = watch.GetDuration();
printf( "Generating double randoms took %lf msec\n", dur );
}
static void nativeComputeDbl() // Floating Point
{
CStopWatch watch;
watch.Start();
double resultDbl = 0.0;
for(int i = 2; i < N_MULTIPLY; i++)
{
for( int j = 0; j < N_GENERATED; j++ )
{
double dbMult = (double)(i * 1.1);
resultDbl = randDbl[j] * dbMult;
resultDbl += 1.555;
outpDbl[j] = resultDbl;
}
}
watch.Stop();
long double dur = watch.GetDuration();
printf( "Double took %lf msec\n", dur );
}
static void nativeComputeTrg() // Trigonometry
{
CStopWatch watch;
watch.Start();
double resultDbl = 0.0;
for(int i = 2; i < N_MULTIPLY; i++)
{
for( int j = 0; j < N_GENERATED; j++ )
{
double dbMult = (double)(i * 2 * M_PI);
resultDbl = randDbl[j] + sin(dbMult);
resultDbl += 0.375;
outpDbl[j] = resultDbl;
}
}
watch.Stop();
long double dur = watch.GetDuration();
printf( "Trig took %lf msec\n", dur );
}
// ==========================================================================
int main(int argc, char* argv[])
{
if (argc > 1)
{
N_MULTIPLY = atol(argv[1]);
}
time_t tt;
srand(time(&tt));
generate_dbl_randoms();
nativeComputeTrg();
nativeComputeDbl();
generate_randoms();
nativeCompute();
printf( "Finita\n" );
return 0;
}
|
| | |