Информация об изменениях

Сообщение Re: Очередной "шедевр" от CLang :-) от 12.03.2017 5:45

Изменено 12.03.2017 6:43 Serg27

Re: Очередной "шедевр" от CLang :-)
После того как я послал bug report в MS, я решил проверить, а как справляется с этим вырожденным примером CLang (по мнению многих лучший компилятор нашего времени). Так как toolset Clang установлен у меня в VS2015, то это делается переключением toolset в настройках проекта.
  Code
#include <time.h>
#include <iostream>

using namespace std;

constexpr auto N_MULTIPLY = 1000000;// 10000000;
constexpr int N_GENERATED = 1000;
namespace
{
    double outputs_dbl[N_GENERATED];
}
template<typename F> void Measure(F f)
{
    for (int i = 2; i<N_MULTIPLY; i++) {
        for (int j = 0; j<N_GENERATED; j++)  f(i, j);
    }
}
template<typename F> void Measure2(F f)
{
    int i = 1;
    for (i = 2; i<N_MULTIPLY; i++) {
        for (int j = 0; j<N_GENERATED; j++)  f(i, j);
    }
    if (i == 0) cout << "msvc";
}

void fun1(int i, int j)
{
    outputs_dbl[j%N_GENERATED] = sin((double)i);
}
inline void fun2(int i, int j)
{
    outputs_dbl[j] = sin((double)i);
}
int main()
{
    auto start = clock();
    Measure(fun1);
    auto finish = clock();
    double duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure(fun1) - " << duration << " s." << endl;
//    cout << outputs_dbl[0] << " " << outputs_dbl[N_GENERATED - 1] << " " << sin((double)(N_MULTIPLY - 1)) << endl;

    start = clock();
    Measure(fun2);
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure(fun2) - " << duration << " s." << endl;

    start = clock();
    Measure2(fun1);
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure2(fun1) - " << duration << " s." << endl;

    start = clock();
    Measure2(fun2);
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure2(fun2) - " << duration << " s." << endl;

}

MS VC++ результат:

Measure(fun1) — 1.481 s.
Measure(fun2) — 26.168 s.
Measure2(fun1) — 1.392 s.
Measure2(fun2) — 0.207 s.

CLang результат:

Measure(fun1) — 30.267 s.
Measure(fun2) — 27.868 s.
Measure2(fun1) — 29.742 s.
Measure2(fun2) — 27.921 s.

командная строка компилятора:

-fpic "stdafx.h" -fstack-protector "x64\Release\" -fno-strict-aliasing -ffunction-sections -gline-tables-only -O3 -x c++-header -D "NDEBUG" -D "_CONSOLE" -D "_UNICODE" -D "UNICODE" -fno-rtti -fomit-frame-pointer -fdata-sections -fno-ms-compatibility -fexceptions -o "x64\Release\testRSDN.obj" -fms-extensions -fno-short-enums


Вывод в стиле ТС :))
!!!Как видно Clang уступает MSVC и вообще не пригоден к использованию!!!!
Re: Очередной "шедевр" от CLang :-)
После того как я послал bug report в MS, я решил проверить, а как справляется с этим вырожденным примером CLang (по мнению многих лучший компилятор нашего времени). Так как toolset Clang установлен у меня в VS2015, то это делается переключением toolset в настройках проекта.
  Code
#include <cmath>
#include <time.h>
#include <iostream>

using namespace std;

constexpr auto N_MULTIPLY = 1000000;// 10000000;
constexpr int N_GENERATED = 1000;
namespace
{
    double outputs_dbl[N_GENERATED];
}
template<typename F> void Measure(F f)
{
    for (int i = 2; i<N_MULTIPLY; i++) {
        for (int j = 0; j<N_GENERATED; j++)  f(i, j);
    }
}
template<typename F> void Measure2(F f)
{
    int i = 1;
    for (i = 2; i<N_MULTIPLY; i++) {
        for (int j = 0; j<N_GENERATED; j++)  f(i, j);
    }
    if (i == 0) cout << "msvc";
}

void fun1(int i, int j)
{
    outputs_dbl[j%N_GENERATED] = sin((double)i);
}
inline void fun2(int i, int j)
{
    outputs_dbl[j] = sin((double)i);
}
int main()
{
    auto start = clock();
    Measure(fun1);
    auto finish = clock();
    double duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure(fun1) - " << duration << " s." << endl;
//    cout << outputs_dbl[0] << " " << outputs_dbl[N_GENERATED - 1] << " " << sin((double)(N_MULTIPLY - 1)) << endl;

    start = clock();
    Measure(fun2);
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure(fun2) - " << duration << " s." << endl;

    start = clock();
    Measure2(fun1);
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure2(fun1) - " << duration << " s." << endl;

    start = clock();
    Measure2(fun2);
    finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "Measure2(fun2) - " << duration << " s." << endl;

}

MS VC++ результат:

Measure(fun1) — 1.481 s.
Measure(fun2) — 26.168 s.
Measure2(fun1) — 1.392 s.
Measure2(fun2) — 0.207 s.

CLang результат:

Measure(fun1) — 30.267 s.
Measure(fun2) — 27.868 s.
Measure2(fun1) — 29.742 s.
Measure2(fun2) — 27.921 s.

командная строка компилятора:

-fpic "stdafx.h" -fstack-protector "x64\Release\" -fno-strict-aliasing -ffunction-sections -gline-tables-only -O3 -x c++-header -D "NDEBUG" -D "_CONSOLE" -D "_UNICODE" -D "UNICODE" -fno-rtti -fomit-frame-pointer -fdata-sections -fno-ms-compatibility -fexceptions -o "x64\Release\testRSDN.obj" -fms-extensions -fno-short-enums


Вывод в стиле ТС :))
!!!Как видно Clang уступает MSVC и вообще не пригоден к использованию!!!!