Замена типа переменной long int на long long без вычислений замедляет код на 15%
От: getch  
Дата: 30.08.13 15:41
Оценка:
Короткий пример:
// Windows 7 x86, Intel i7 x86, Project Win32.

#include <iostream>
#include <windows.h>

void Print( long long Amount, unsigned long long CalcBars )
{
  static int ProcentCount = 0;
  static long long Count = 0, CountP = 0, Procent = Amount / 100;
  static unsigned long int StartTime = GetTickCount();

  CountP++;

    if (CountP > Procent)
    {
      Count += CountP;

      CountP = 0;
      ProcentCount++;
      
   unsigned long int DeltaTime = GetTickCount() - StartTime;

      if (Count != 0)
     std::cout << "Finished " << ProcentCount << "%, Time = " << DeltaTime / 1000 <<
                     " / " << (int)((double)DeltaTime * (Amount - Count) / (Count * 1000.)) << std::endl;

// Замедление в основном происходит здесь    
      if (DeltaTime != 0) 
        std::cout << "Average Velocity = " << CalcBars / DeltaTime << " thousands bars/sec." << std::endl;
    }
  
 return;
}

#define AMOUNT 100000000000LL

int main(int argc, char* argv[])
{
  unsigned long int CalcBars = 0, CurrentBar = 100;
// Замена на эту строчку замедляет выполнение программы на ~ 15%.
//  unsigned long long CalcBars = 0, CurrentBar = 100;
  
  for (long long i = 0; i < AMOUNT; i++)
  {
    Print(AMOUNT, CalcBars);

    CalcBars += CurrentBar;
  }

  return(0);
}


В программе цикл на 100 млрд, при этом 100 раз (каждый процент выполнения) через cout выводятся данные в секундах: сколько времени посчиталось и сколько осталось считать.
Если в main заменить строчку, согласно комментарию, то происходит замедление выполнения кода на 15%: вместо 189-и секунд вычисления длятся 220 секунд.

Запускаю под VS 2012 Ultimate SP1 Windows 7 x86, Intel i5, Console Project Win32 Release.

Три вопроса:
1. У кого-нибудь воспроизводится данное чудовищное замедление?

2. Каковы реальные причины этого?

3. Как правильно писать код, чтобы ради ускорения думать только об алгоритмической оптимизации, а не о таких далеко не очевидных технических нюансах?


Командная строка компилятора:
/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /Fd"Release\vc110.pdb" /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\Test.pch"

Вроде (второй день на Visual Studio), это должно давать наибыстрейшее исполнение кода.

Данные профилировщика:


P.S. Согласен, что cout не совсем корректно использовать между вызовами GetTickCount, но в данном примере это не влияет на результат.
Re: Замена типа переменной long int на long long без вычислений замедляет код на
От: rg45 СССР  
Дата: 30.08.13 16:55
Оценка:
Здравствуйте, getch, Вы писали:

G>Короткий пример:

G>
G>int main(int argc, char* argv[])
G>{
G> . . .
G>  unsigned long int CalcBars = 0, CurrentBar = 100;
G>// Замена на эту строчку замедляет выполнение программы на ~ 15%.
G>//  unsigned long long CalcBars = 0, CurrentBar = 100;
  
G>  for (long long i = 0; i < AMOUNT; i++)
G>  {
G>    Print(AMOUNT, CalcBars);

G>    CalcBars += CurrentBar;
G>  }
G>}
G>


G>В программе цикл на 100 млрд, при этом 100 раз (каждый процент выполнения) через cout выводятся данные в секундах: сколько времени посчиталось и сколько осталось считать.

G>Если в main заменить строчку, согласно комментарию, то происходит замедление выполнения кода на 15%: вместо 189-и секунд вычисления длятся 220 секунд.

G>Запускаю под VS 2012 Ultimate SP1 Windows 7 x86, Intel i5, Console Project Win32 Release.


G>Три вопроса:

G>[b]1. . .

G>2. Каковы реальные причины этого?


G>3. . .


Ну да, на 32-битной платформе 32-битные числа работают быстрее, чем 64-битные... И что тут удивительного?
--
Справедливость выше закона. А человечность выше справедливости.
Re: Замена типа переменной long int на long long без вычислений замедляет код на
От: watchmaker  
Дата: 30.08.13 16:59
Оценка:
Проблема твоего теста — в нём отсутствует полезная нагрузка. Гонять холостой цикл много-много раз, конечно, интересно, но лучше сначала написать полезное тело. Преждевременная оптимизация ещё ненаписанного кода — это вообще что-то странное.



G>В программе цикл на 100 млрд, при этом 100 раз (каждый процент выполнения) через cout выводятся данные в секундах: сколько времени посчиталось и сколько осталось считать.

Ну вообще, когда нужно выполнить много мелких операций, имеет смысл объединять их в блоки, соответственно, выполняя блок целиком. Помимо уменьшения числа проверок это откроет компилятору некоторые пути оптимизации (вроде автовекторизации или автораспараллеливания) — сплошная выгода.
Re[2]: Замена типа переменной long int на long long без вычислений замедляет код
От: niXman Ниоткуда https://github.com/niXman
Дата: 30.08.13 17:12
Оценка:
Здравствуйте, watchmaker, Вы писали:

W>Ну вообще, когда нужно выполнить много мелких операций, имеет смысл объединять их в блоки, соответственно, выполняя блок целиком.

это зовется SIMD, ну да
пачка бумаги А4 стОит 2000 р, в ней 500 листов. получается, лист обычной бумаги стОит дороже имперского рубля =)
Re: Замена типа переменной long int на long long без вычислений замедляет код на
От: getch  
Дата: 30.08.13 17:16
Оценка:
Дело в том, что я занимаюсь написанием решения довольно ресурсоемкой задачи. И сейчас нахожусь на этапе ускорения через поиски наиболее оптимальных алгоритмов. Совершенно случайно наткнулся на этот случай, т.к. скорость выполнения упала на 5% программы, которая очень много всего вычисляет. Это сильно удивило. Тогда придумал представленный выше короткий пример, чтобы разобраться.

Отлично понимаю, что операции с 64-битными числами могут выполняться медленнее на 32-битной платформе. Но тут надо внимательно посмотреть на код выше.

Если оставить long long
unsigned long long CalcBars = 0, CurrentBar = 100;

и просто закомментировать этот кусок
// Замедление в основном происходит здесь    
      if (DeltaTime != 0) 
        std::cout << "Average Velocity = " << CalcBars / DeltaTime << " thousands bars/sec." << std::endl;

, то замедления не будет. Удивляет то, что из 100 млрд различных операций, данный кусок кода выполняется всего 100 раз. При этом замедление аж на 15%.

Более того (сейчас попробовал), если этот кусок заменить вообще на абсурдный:

// Замедление в основном происходит здесь      
      if (DeltaTime < DeltaTime) 
        std::cout << "Average Velocity = " << CalcBars / DeltaTime << " thousands bars/sec." << std::endl;


то будет замедление, хоть он ни разу и не выполнится, как при полном закомментировании.

Попробуйте у себя запустить.
Re[2]: Замена типа переменной long int на long long без вычислений замедляет код
От: Muxa  
Дата: 30.08.13 17:23
Оценка:
А если так:
      if (DeltaTime == 0) {}
      else
        std::cout << "Average Velocity = " << CalcBars / DeltaTime << " thousands bars/sec." << std::endl;

?
Re[3]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 17:26
Оценка:
M>А если так:
M>
M>      if (DeltaTime == 0) {}
M>      else
M>        std::cout << "Average Velocity = " << CalcBars / DeltaTime << " thousands bars/sec." << std::endl;
M>

M>?

Замедляет все равно. Попробуйте и у себя.
Re[4]: Замена типа переменной long int на long long без вычислений замедляет код
От: Muxa  
Дата: 30.08.13 18:03
Оценка:
G>Замедляет все равно. Попробуйте и у себя.
это был совет не как избавиться от замедления, а как попытаться сделать быстрее оба случая.

машина х64. конфигурация х86.
компилировал так:

/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /Fd"Release\vc110.pdb" /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /EHsc /nologo

с вашими опциями не скомпилилось.

  int
Finished 1%, Time = 3 / 299
Average Velocity = 401768 thousands bars/sec.
Finished 2%, Time = 6 / 296
Average Velocity = 401702 thousands bars/sec.
Finished 3%, Time = 9 / 294
Average Velocity = 401017 thousands bars/sec.
Finished 4%, Time = 12 / 292
Average Velocity = 46564 thousands bars/sec.
Finished 5%, Time = 15 / 289
Average Velocity = 117039 thousands bars/sec.
Finished 6%, Time = 18 / 286
Average Velocity = 164062 thousands bars/sec.
Finished 7%, Time = 21 / 283
Average Velocity = 197669 thousands bars/sec.
Finished 8%, Time = 24 / 279
Average Velocity = 46683 thousands bars/sec.
Finished 9%, Time = 27 / 276
Average Velocity = 85949 thousands bars/sec.
Finished 10%, Time = 30 / 273
Average Velocity = 117459 thousands bars/sec.
Finished 11%, Time = 33 / 270
Average Velocity = 14621 thousands bars/sec.
Finished 12%, Time = 36 / 267
Average Velocity = 46783 thousands bars/sec.
Finished 13%, Time = 39 / 263
Average Velocity = 74039 thousands bars/sec.
Finished 14%, Time = 42 / 260
Average Velocity = 97393 thousands bars/sec.
Finished 15%, Time = 45 / 257
Average Velocity = 23223 thousands bars/sec.
Finished 16%, Time = 48 / 254
Average Velocity = 46847 thousands bars/sec.
Finished 17%, Time = 51 / 251
Average Velocity = 67650 thousands bars/sec.
Finished 18%, Time = 54 / 248
Average Velocity = 7489 thousands bars/sec.
Finished 19%, Time = 57 / 245
Average Velocity = 28196 thousands bars/sec.
Finished 20%, Time = 60 / 242
Average Velocity = 46827 thousands bars/sec.
Finished 21%, Time = 63 / 239
Average Velocity = 63677 thousands bars/sec.
Finished 22%, Time = 66 / 236
Average Velocity = 14639 thousands bars/sec.
Finished 23%, Time = 69 / 233
Average Velocity = 31427 thousands bars/sec.
Finished 24%, Time = 72 / 230
Average Velocity = 46823 thousands bars/sec.
Finished 25%, Time = 75 / 227
Average Velocity = 4339 thousands bars/sec.
Finished 26%, Time = 78 / 224
Average Velocity = 19581 thousands bars/sec.
Finished 27%, Time = 81 / 221
Average Velocity = 33699 thousands bars/sec.
Finished 28%, Time = 84 / 218
Average Velocity = 46820 thousands bars/sec.
Finished 29%, Time = 87 / 215
Average Velocity = 10199 thousands bars/sec.
Finished 30%, Time = 91 / 212
Average Velocity = 23215 thousands bars/sec.
Finished 31%, Time = 94 / 209
Average Velocity = 35402 thousands bars/sec.
Finished 32%, Time = 97 / 206
Average Velocity = 2569 thousands bars/sec.
Finished 33%, Time = 100 / 203
Average Velocity = 14638 thousands bars/sec.
Finished 34%, Time = 103 / 200
Average Velocity = 26002 thousands bars/sec.
Finished 35%, Time = 106 / 197
Average Velocity = 36716 thousands bars/sec.
Finished 36%, Time = 109 / 194
Average Velocity = 7487 thousands bars/sec.
Finished 37%, Time = 112 / 191
Average Velocity = 18124 thousands bars/sec.
Finished 38%, Time = 115 / 187
Average Velocity = 28200 thousands bars/sec.
Finished 39%, Time = 118 / 184
Average Velocity = 1435 thousands bars/sec.
Finished 40%, Time = 121 / 181
Average Velocity = 11426 thousands bars/sec.
Finished 41%, Time = 124 / 178
Average Velocity = 20934 thousands bars/sec.
Finished 42%, Time = 127 / 175
Average Velocity = 29988 thousands bars/sec.
Finished 43%, Time = 130 / 172
Average Velocity = 5661 thousands bars/sec.
Finished 44%, Time = 133 / 169
Average Velocity = 14651 thousands bars/sec.
Finished 45%, Time = 136 / 166
Average Velocity = 23244 thousands bars/sec.
Finished 46%, Time = 139 / 163
Average Velocity = 646 thousands bars/sec.
Finished 47%, Time = 142 / 160
Average Velocity = 9170 thousands bars/sec.
Finished 48%, Time = 145 / 157
Average Velocity = 17342 thousands bars/sec.
Finished 49%, Time = 148 / 154
Average Velocity = 25183 thousands bars/sec.
Finished 50%, Time = 151 / 151
Average Velocity = 4346 thousands bars/sec.
Finished 51%, Time = 154 / 148
Average Velocity = 12129 thousands bars/sec.
Finished 52%, Time = 157 / 145
Average Velocity = 19614 thousands bars/sec.
Finished 53%, Time = 160 / 142
Average Velocity = 64 thousands bars/sec.
Finished 54%, Time = 163 / 139
Average Velocity = 7496 thousands bars/sec.
Finished 55%, Time = 166 / 136
Average Velocity = 14660 thousands bars/sec.
Finished 56%, Time = 169 / 133
Average Velocity = 21569 thousands bars/sec.
Finished 57%, Time = 172 / 130
Average Velocity = 3349 thousands bars/sec.
Finished 58%, Time = 175 / 127
Average Velocity = 10207 thousands bars/sec.
Finished 59%, Time = 178 / 124
Average Velocity = 16830 thousands bars/sec.
Finished 60%, Time = 181 / 121
Average Velocity = 23235 thousands bars/sec.
Finished 61%, Time = 184 / 118
Average Velocity = 6200 thousands bars/sec.
Finished 62%, Time = 187 / 115
Average Velocity = 12571 thousands bars/sec.
Finished 63%, Time = 190 / 112
Average Velocity = 18741 thousands bars/sec.
Finished 64%, Time = 193 / 109
Average Velocity = 2571 thousands bars/sec.
Finished 65%, Time = 196 / 106
Average Velocity = 8703 thousands bars/sec.
Finished 66%, Time = 200 / 103
Average Velocity = 14649 thousands bars/sec.
Finished 67%, Time = 203 / 100
Average Velocity = 20420 thousands bars/sec.
Finished 68%, Time = 206 / 96
Average Velocity = 5177 thousands bars/sec.
Finished 69%, Time = 209 / 93
Average Velocity = 10917 thousands bars/sec.
Finished 70%, Time = 212 / 90
Average Velocity = 16494 thousands bars/sec.
Finished 71%, Time = 215 / 87
Average Velocity = 1948 thousands bars/sec.
Finished 72%, Time = 218 / 84
Average Velocity = 7495 thousands bars/sec.
Finished 73%, Time = 221 / 81
Average Velocity = 12889 thousands bars/sec.
Finished 74%, Time = 224 / 78
Average Velocity = 18139 thousands bars/sec.
Finished 75%, Time = 227 / 75
Average Velocity = 4344 thousands bars/sec.
Finished 76%, Time = 230 / 72
Average Velocity = 9568 thousands bars/sec.
Finished 77%, Time = 233 / 69
Average Velocity = 14657 thousands bars/sec.
Finished 78%, Time = 236 / 66
Average Velocity = 1436 thousands bars/sec.
Finished 79%, Time = 239 / 63
Average Velocity = 6499 thousands bars/sec.
Finished 80%, Time = 242 / 60
Average Velocity = 11435 thousands bars/sec.
Finished 81%, Time = 245 / 57
Average Velocity = 16249 thousands bars/sec.
Finished 82%, Time = 248 / 54
Average Velocity = 3653 thousands bars/sec.
Finished 83%, Time = 251 / 51
Average Velocity = 8446 thousands bars/sec.
Finished 84%, Time = 254 / 48
Average Velocity = 13125 thousands bars/sec.
Finished 85%, Time = 257 / 45
Average Velocity = 1009 thousands bars/sec.
Finished 86%, Time = 260 / 42
Average Velocity = 5665 thousands bars/sec.
Finished 87%, Time = 263 / 39
Average Velocity = 10216 thousands bars/sec.
Finished 88%, Time = 266 / 36
Average Velocity = 14663 thousands bars/sec.
Finished 89%, Time = 269 / 33
Average Velocity = 3071 thousands bars/sec.
Finished 90%, Time = 272 / 30
Average Velocity = 7499 thousands bars/sec.
Finished 91%, Time = 275 / 27
Average Velocity = 11830 thousands bars/sec.
Finished 92%, Time = 278 / 24
Average Velocity = 646 thousands bars/sec.
Finished 93%, Time = 281 / 21
Average Velocity = 4958 thousands bars/sec.
Finished 94%, Time = 284 / 18
Average Velocity = 9178 thousands bars/sec.
Finished 95%, Time = 287 / 15
Average Velocity = 13309 thousands bars/sec.
Finished 96%, Time = 290 / 12
Average Velocity = 2574 thousands bars/sec.
Finished 97%, Time = 293 / 9
Average Velocity = 6689 thousands bars/sec.
Finished 98%, Time = 296 / 6
Average Velocity = 10720 thousands bars/sec.
Finished 99%, Time = 299 / 3
Average Velocity = 335 thousands bars/sec.
  long
Finished 1%, Time = 2 / 270
Average Velocity = 36630036 thousands bars/sec.
Finished 2%, Time = 5 / 266
Average Velocity = 36737692 thousands bars/sec.
Finished 3%, Time = 8 / 263
Average Velocity = 36841458 thousands bars/sec.
Finished 4%, Time = 10 / 260
Average Velocity = 36788374 thousands bars/sec.
Finished 5%, Time = 13 / 258
Average Velocity = 36797174 thousands bars/sec.
Finished 6%, Time = 16 / 255
Average Velocity = 36769211 thousands bars/sec.
Finished 7%, Time = 19 / 252
Average Velocity = 36811106 thousands bars/sec.
Finished 8%, Time = 21 / 249
Average Velocity = 36840893 thousands bars/sec.
Finished 9%, Time = 24 / 247
Average Velocity = 36839950 thousands bars/sec.
Finished 10%, Time = 27 / 244
Average Velocity = 36818851 thousands bars/sec.
Finished 11%, Time = 29 / 241
Average Velocity = 36801605 thousands bars/sec.
Finished 12%, Time = 32 / 239
Average Velocity = 36770338 thousands bars/sec.
Finished 13%, Time = 35 / 236
Average Velocity = 36791758 thousands bars/sec.
Finished 14%, Time = 38 / 233
Average Velocity = 36810138 thousands bars/sec.
Finished 15%, Time = 40 / 230
Average Velocity = 36812526 thousands bars/sec.
Finished 16%, Time = 43 / 228
Average Velocity = 36840045 thousands bars/sec.
Finished 17%, Time = 46 / 225
Average Velocity = 36840394 thousands bars/sec.
Finished 18%, Time = 48 / 222
Average Velocity = 36864094 thousands bars/sec.
Finished 19%, Time = 51 / 219
Average Velocity = 36873871 thousands bars/sec.
Finished 20%, Time = 54 / 216
Average Velocity = 36882676 thousands bars/sec.
Finished 21%, Time = 56 / 214
Average Velocity = 36880927 thousands bars/sec.
Finished 22%, Time = 59 / 211
Average Velocity = 36888613 thousands bars/sec.
Finished 23%, Time = 62 / 208
Average Velocity = 36895633 thousands bars/sec.
Finished 24%, Time = 65 / 206
Average Velocity = 36884490 thousands bars/sec.
Finished 25%, Time = 67 / 203
Average Velocity = 36899824 thousands bars/sec.
Finished 26%, Time = 70 / 200
Average Velocity = 36897227 thousands bars/sec.
Finished 27%, Time = 73 / 197
Average Velocity = 36895326 thousands bars/sec.
Finished 28%, Time = 75 / 195
Average Velocity = 36900855 thousands bars/sec.
Finished 29%, Time = 78 / 192
Average Velocity = 36906004 thousands bars/sec.
Finished 30%, Time = 81 / 189
Average Velocity = 36911265 thousands bars/sec.
Finished 31%, Time = 83 / 186
Average Velocity = 36915748 thousands bars/sec.
Finished 32%, Time = 86 / 184
Average Velocity = 36919952 thousands bars/sec.
Finished 33%, Time = 89 / 181
Average Velocity = 36923903 thousands bars/sec.
Finished 34%, Time = 92 / 178
Average Velocity = 36927621 thousands bars/sec.
Finished 35%, Time = 94 / 176
Average Velocity = 36931128 thousands bars/sec.
Finished 36%, Time = 97 / 173
Average Velocity = 36922698 thousands bars/sec.
Finished 37%, Time = 100 / 170
Average Velocity = 36926516 thousands bars/sec.
Finished 38%, Time = 102 / 167
Average Velocity = 36929775 thousands bars/sec.
Finished 39%, Time = 105 / 165
Average Velocity = 36932867 thousands bars/sec.
Finished 40%, Time = 108 / 162
Average Velocity = 36935805 thousands bars/sec.
Finished 41%, Time = 111 / 159
Average Velocity = 36928287 thousands bars/sec.
Finished 42%, Time = 113 / 157
Average Velocity = 36936390 thousands bars/sec.
Finished 43%, Time = 116 / 154
Average Velocity = 36939042 thousands bars/sec.
Finished 44%, Time = 119 / 151
Average Velocity = 36941573 thousands bars/sec.
Finished 45%, Time = 121 / 148
Average Velocity = 36943992 thousands bars/sec.
Finished 46%, Time = 124 / 146
Average Velocity = 36946604 thousands bars/sec.
Finished 47%, Time = 127 / 143
Average Velocity = 36948814 thousands bars/sec.
Finished 48%, Time = 129 / 140
Average Velocity = 36955484 thousands bars/sec.
Finished 49%, Time = 132 / 138
Average Velocity = 36952964 thousands bars/sec.
Finished 50%, Time = 135 / 135
Average Velocity = 36959285 thousands bars/sec.
Finished 51%, Time = 137 / 132
Average Velocity = 36957057 thousands bars/sec.
Finished 52%, Time = 140 / 129
Average Velocity = 36958854 thousands bars/sec.
Finished 53%, Time = 143 / 127
Average Velocity = 36956461 thousands bars/sec.
Finished 54%, Time = 146 / 124
Average Velocity = 36958455 thousands bars/sec.
Finished 55%, Time = 148 / 121
Average Velocity = 36963856 thousands bars/sec.
Finished 56%, Time = 151 / 119
Average Velocity = 36965404 thousands bars/sec.
Finished 57%, Time = 154 / 116
Average Velocity = 36967138 thousands bars/sec.
Finished 58%, Time = 156 / 113
Average Velocity = 36961273 thousands bars/sec.
Finished 59%, Time = 159 / 110
Average Velocity = 36966260 thousands bars/sec.
Finished 60%, Time = 162 / 108
Average Velocity = 36971310 thousands bars/sec.
Finished 61%, Time = 164 / 105
Average Velocity = 36972609 thousands bars/sec.
Finished 62%, Time = 167 / 102
Average Velocity = 36970560 thousands bars/sec.
Finished 63%, Time = 170 / 100
Average Velocity = 36975302 thousands bars/sec.
Finished 64%, Time = 173 / 97
Average Velocity = 36976479 thousands bars/sec.
Finished 65%, Time = 175 / 94
Average Velocity = 36977620 thousands bars/sec.
Finished 66%, Time = 178 / 91
Average Velocity = 36982041 thousands bars/sec.
Finished 67%, Time = 181 / 89
Average Velocity = 36979799 thousands bars/sec.
Finished 68%, Time = 183 / 86
Average Velocity = 36971591 thousands bars/sec.
Finished 69%, Time = 186 / 83
Average Velocity = 36972736 thousands bars/sec.
Finished 70%, Time = 189 / 81
Average Velocity = 36967795 thousands bars/sec.
Finished 71%, Time = 192 / 78
Average Velocity = 36968961 thousands bars/sec.
Finished 72%, Time = 194 / 75
Average Velocity = 36970095 thousands bars/sec.
Finished 73%, Time = 197 / 73
Average Velocity = 36968389 thousands bars/sec.
Finished 74%, Time = 200 / 70
Average Velocity = 36963775 thousands bars/sec.
Finished 75%, Time = 202 / 67
Average Velocity = 36962200 thousands bars/sec.
Finished 76%, Time = 205 / 64
Average Velocity = 36960486 thousands bars/sec.
Finished 77%, Time = 208 / 62
Average Velocity = 36961655 thousands bars/sec.
Finished 78%, Time = 211 / 59
Average Velocity = 36960168 thousands bars/sec.
Finished 79%, Time = 213 / 56
Average Velocity = 36964079 thousands bars/sec.
Finished 80%, Time = 216 / 54
Average Velocity = 36965160 thousands bars/sec.
Finished 81%, Time = 219 / 51
Average Velocity = 36966214 thousands bars/sec.
Finished 82%, Time = 221 / 48
Average Velocity = 36967243 thousands bars/sec.
Finished 83%, Time = 224 / 45
Average Velocity = 36965777 thousands bars/sec.
Finished 84%, Time = 227 / 43
Average Velocity = 36966787 thousands bars/sec.
Finished 85%, Time = 229 / 40
Average Velocity = 36967772 thousands bars/sec.
Finished 86%, Time = 232 / 37
Average Velocity = 36963809 thousands bars/sec.
Finished 87%, Time = 235 / 35
Average Velocity = 36964806 thousands bars/sec.
Finished 88%, Time = 238 / 32
Average Velocity = 36965936 thousands bars/sec.
Finished 89%, Time = 240 / 29
Average Velocity = 36966887 thousands bars/sec.
Finished 90%, Time = 243 / 27
Average Velocity = 36963110 thousands bars/sec.
Finished 91%, Time = 246 / 24
Average Velocity = 36964071 thousands bars/sec.
Finished 92%, Time = 248 / 21
Average Velocity = 36965011 thousands bars/sec.
Finished 93%, Time = 251 / 18
Average Velocity = 36965931 thousands bars/sec.
Finished 94%, Time = 254 / 16
Average Velocity = 36964651 thousands bars/sec.
Finished 95%, Time = 256 / 13
Average Velocity = 36965555 thousands bars/sec.
Finished 96%, Time = 259 / 10
Average Velocity = 36966441 thousands bars/sec.
Finished 97%, Time = 262 / 8
Average Velocity = 36967308 thousands bars/sec.
Finished 98%, Time = 265 / 5
Average Velocity = 36968297 thousands bars/sec.
Finished 99%, Time = 267 / 2
Average Velocity = 36960433 thousands bars/sec.
Re[5]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 19:07
Оценка:
Аналогично, запустил на x64-машине с x86-конфигурацией.

Не понял, почему у вас не запустился мой вариант командной строки компилятора:

/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /Fd"Release\vc110.pdb" /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\Test.pch"

подчеркнул отличие от вашей конфигурации. Не силен пока в их интерпретации. Но, вроде, ничего существенного они не дают.

Результаты работы:
  int
Finished 1%, Time = 1 / 191
Average Velocity = 628620 thousands bars/se
Finished 2%, Time = 3 / 189
Average Velocity = 628458 thousands bars/se
Finished 3%, Time = 5 / 187
Average Velocity = 628512 thousands bars/se
Finished 4%, Time = 7 / 185
Average Velocity = 73561 thousands bars/sec
Finished 5%, Time = 9 / 183
Average Velocity = 184734 thousands bars/se
Finished 6%, Time = 11 / 181
Average Velocity = 259140 thousands bars/se
Finished 7%, Time = 13 / 179
Average Velocity = 312383 thousands bars/se
Finished 8%, Time = 15 / 177
Average Velocity = 73637 thousands bars/sec
Finished 9%, Time = 17 / 175
Average Velocity = 135209 thousands bars/se
Finished 10%, Time = 19 / 173
Average Velocity = 184581 thousands bars/se
Finished 11%, Time = 21 / 172
Average Velocity = 22968 thousands bars/sec
Finished 12%, Time = 23 / 170
Average Velocity = 73510 thousands bars/sec
Finished 13%, Time = 25 / 168
Average Velocity = 116255 thousands bars/se
Finished 14%, Time = 27 / 166
Average Velocity = 152973 thousands bars/se
Finished 15%, Time = 28 / 164
Average Velocity = 36485 thousands bars/sec
Finished 16%, Time = 30 / 161
Average Velocity = 73635 thousands bars/sec
Finished 17%, Time = 32 / 160
Average Velocity = 106416 thousands bars/se
Finished 18%, Time = 34 / 158
Average Velocity = 11774 thousands bars/sec
Finished 19%, Time = 36 / 156
Average Velocity = 44348 thousands bars/sec
Finished 20%, Time = 38 / 154
Average Velocity = 73651 thousands bars/sec
Finished 21%, Time = 40 / 152
Average Velocity = 100152 thousands bars/se
Finished 22%, Time = 42 / 150
Average Velocity = 23027 thousands bars/sec
Finished 23%, Time = 44 / 148
Average Velocity = 49435 thousands bars/sec
Finished 24%, Time = 46 / 146
Average Velocity = 73636 thousands bars/sec
Finished 25%, Time = 48 / 144
Average Velocity = 6825 thousands bars/sec.
Finished 26%, Time = 50 / 142
Average Velocity = 30810 thousands bars/sec
Finished 27%, Time = 52 / 140
Average Velocity = 53029 thousands bars/sec
Finished 28%, Time = 53 / 138
Average Velocity = 73667 thousands bars/sec
Finished 29%, Time = 55 / 136
Average Velocity = 16049 thousands bars/sec
Finished 30%, Time = 57 / 134
Average Velocity = 36535 thousands bars/sec
Finished 31%, Time = 59 / 132
Average Velocity = 55710 thousands bars/sec
Finished 32%, Time = 61 / 131
Average Velocity = 4043 thousands bars/sec.
Finished 33%, Time = 63 / 129
Average Velocity = 23047 thousands bars/sec
Finished 34%, Time = 65 / 127
Average Velocity = 40936 thousands bars/sec
Finished 35%, Time = 67 / 125
Average Velocity = 57806 thousands bars/sec
Finished 36%, Time = 69 / 123
Average Velocity = 11790 thousands bars/sec
Finished 37%, Time = 71 / 121
Average Velocity = 28537 thousands bars/sec
Finished 38%, Time = 73 / 119
Average Velocity = 44405 thousands bars/sec
Finished 39%, Time = 75 / 117
Average Velocity = 2260 thousands bars/sec.
Finished 40%, Time = 77 / 115
Average Velocity = 17992 thousands bars/sec
Finished 41%, Time = 78 / 113
Average Velocity = 32953 thousands bars/sec
Finished 42%, Time = 80 / 111
Average Velocity = 47207 thousands bars/sec
Finished 43%, Time = 82 / 109
Average Velocity = 8910 thousands bars/sec.
Finished 44%, Time = 84 / 107
Average Velocity = 23057 thousands bars/sec
Finished 45%, Time = 86 / 105
Average Velocity = 36571 thousands bars/sec
Finished 46%, Time = 88 / 103
Average Velocity = 1016 thousands bars/sec.
Finished 47%, Time = 90 / 102
Average Velocity = 14426 thousands bars/sec
Finished 48%, Time = 92 / 100
Average Velocity = 27275 thousands bars/sec
Finished 49%, Time = 94 / 98
Average Velocity = 39604 thousands bars/sec
Finished 50%, Time = 96 / 96
Average Velocity = 6833 thousands bars/sec.
Finished 51%, Time = 98 / 94
Average Velocity = 19075 thousands bars/sec
Finished 52%, Time = 100 / 92
Average Velocity = 30839 thousands bars/sec
Finished 53%, Time = 102 / 90
Average Velocity = 101 thousands bars/sec.
Finished 54%, Time = 104 / 88
Average Velocity = 11783 thousands bars/sec
Finished 55%, Time = 106 / 86
Average Velocity = 23035 thousands bars/sec
Finished 56%, Time = 107 / 84
Average Velocity = 33886 thousands bars/sec
Finished 57%, Time = 109 / 82
Average Velocity = 5265 thousands bars/sec.
Finished 58%, Time = 111 / 80
Average Velocity = 16047 thousands bars/sec
Finished 59%, Time = 113 / 79
Average Velocity = 26463 thousands bars/sec
Finished 60%, Time = 115 / 77
Average Velocity = 36530 thousands bars/sec
Finished 61%, Time = 117 / 75
Average Velocity = 9746 thousands bars/sec.
Finished 62%, Time = 119 / 73
Average Velocity = 19765 thousands bars/sec
Finished 63%, Time = 121 / 71
Average Velocity = 29464 thousands bars/sec
Finished 64%, Time = 123 / 69
Average Velocity = 4043 thousands bars/sec.
Finished 65%, Time = 125 / 67
Average Velocity = 13684 thousands bars/sec
Finished 66%, Time = 127 / 65
Average Velocity = 23035 thousands bars/sec
Finished 67%, Time = 129 / 63
Average Velocity = 32109 thousands bars/sec
Finished 68%, Time = 131 / 61
Average Velocity = 8138 thousands bars/sec.
Finished 69%, Time = 133 / 59
Average Velocity = 17159 thousands bars/sec
Finished 70%, Time = 134 / 57
Average Velocity = 25921 thousands bars/sec
Finished 71%, Time = 136 / 55
Average Velocity = 3060 thousands bars/sec.
Finished 72%, Time = 138 / 53
Average Velocity = 11776 thousands bars/sec
Finished 73%, Time = 140 / 52
Average Velocity = 20253 thousands bars/sec
Finished 74%, Time = 142 / 50
Average Velocity = 28506 thousands bars/sec
Finished 75%, Time = 144 / 48
Average Velocity = 6827 thousands bars/sec.
Finished 76%, Time = 146 / 46
Average Velocity = 15033 thousands bars/sec
Finished 77%, Time = 148 / 44
Average Velocity = 23028 thousands bars/sec
Finished 78%, Time = 150 / 42
Average Velocity = 2257 thousands bars/sec.
Finished 79%, Time = 152 / 40
Average Velocity = 10210 thousands bars/sec
Finished 80%, Time = 154 / 38
Average Velocity = 17966 thousands bars/sec
Finished 81%, Time = 156 / 36
Average Velocity = 25532 thousands bars/sec
Finished 82%, Time = 158 / 34
Average Velocity = 5741 thousands bars/sec.
Finished 83%, Time = 159 / 32
Average Velocity = 13271 thousands bars/sec
Finished 84%, Time = 161 / 30
Average Velocity = 20619 thousands bars/sec
Finished 85%, Time = 163 / 28
Average Velocity = 1585 thousands bars/sec.
Finished 86%, Time = 165 / 26
Average Velocity = 8901 thousands bars/sec.
Finished 87%, Time = 167 / 25
Average Velocity = 16050 thousands bars/sec
Finished 88%, Time = 169 / 23
Average Velocity = 23033 thousands bars/sec
Finished 89%, Time = 171 / 21
Average Velocity = 4825 thousands bars/sec.
Finished 90%, Time = 173 / 19
Average Velocity = 11781 thousands bars/sec
Finished 91%, Time = 175 / 17
Average Velocity = 18582 thousands bars/sec
Finished 92%, Time = 177 / 15
Average Velocity = 1015 thousands bars/sec.
Finished 93%, Time = 179 / 13
Average Velocity = 7787 thousands bars/sec.
Finished 94%, Time = 181 / 11
Average Velocity = 14415 thousands bars/sec
Finished 95%, Time = 183 / 9
Average Velocity = 20901 thousands bars/sec
Finished 96%, Time = 185 / 7
Average Velocity = 4043 thousands bars/sec.
Finished 97%, Time = 186 / 5
Average Velocity = 10503 thousands bars/sec
Finished 98%, Time = 188 / 3
Average Velocity = 16833 thousands bars/sec
Finished 99%, Time = 190 / 1
Average Velocity = 525 thousands bars/sec.


  long
Finished 1%, Time = 2 / 220
Average Velocity = 44843049 thousands bars/sec.
Finished 2%, Time = 4 / 217
Average Velocity = 44984255 thousands bars/sec.
Finished 3%, Time = 6 / 215
Average Velocity = 44937088 thousands bars/sec.
Finished 4%, Time = 8 / 213
Average Velocity = 44984255 thousands bars/sec.
Finished 5%, Time = 11 / 211
Average Velocity = 45016656 thousands bars/sec.
Finished 6%, Time = 13 / 208
Average Velocity = 45038282 thousands bars/sec.
Finished 7%, Time = 15 / 206
Average Velocity = 45053742 thousands bars/sec.
Finished 8%, Time = 17 / 204
Average Velocity = 45065344 thousands bars/sec.
Finished 9%, Time = 19 / 201
Average Velocity = 45072115 thousands bars/sec.
Finished 10%, Time = 22 / 199
Average Velocity = 45079565 thousands bars/sec.
Finished 11%, Time = 24 / 197
Average Velocity = 45113398 thousands bars/sec.
Finished 12%, Time = 26 / 195
Average Velocity = 45116174 thousands bars/sec.
Finished 13%, Time = 28 / 192
Average Velocity = 45118522 thousands bars/sec.
Finished 14%, Time = 31 / 190
Average Velocity = 45120536 thousands bars/sec.
Finished 15%, Time = 33 / 188
Average Velocity = 45142650 thousands bars/sec.
Finished 16%, Time = 35 / 186
Average Velocity = 45122535 thousands bars/sec.
Finished 17%, Time = 37 / 183
Average Velocity = 45123958 thousands bars/sec.
Finished 18%, Time = 39 / 181
Average Velocity = 45125222 thousands bars/sec.
Finished 19%, Time = 42 / 179
Average Velocity = 45126353 thousands bars/sec.
Finished 20%, Time = 44 / 177
Average Velocity = 45127372 thousands bars/sec.
Finished 21%, Time = 46 / 175
Average Velocity = 45127323 thousands bars/sec.
Finished 22%, Time = 48 / 172
Average Velocity = 45128205 thousands bars/sec.
Finished 23%, Time = 50 / 170
Average Velocity = 45129010 thousands bars/sec.
Finished 24%, Time = 53 / 168
Average Velocity = 45129748 thousands bars/sec.
Finished 25%, Time = 55 / 166
Average Velocity = 45129612 thousands bars/sec.
Finished 26%, Time = 57 / 164
Average Velocity = 45118522 thousands bars/sec.
Finished 27%, Time = 59 / 161
Average Velocity = 45130879 thousands bars/sec.
Finished 28%, Time = 62 / 159
Average Velocity = 45131445 thousands bars/sec.
Finished 29%, Time = 64 / 157
Average Velocity = 45131972 thousands bars/sec.
Finished 30%, Time = 66 / 155
Average Velocity = 45131784 thousands bars/sec.
Finished 31%, Time = 68 / 152
Average Velocity = 45132266 thousands bars/sec.
Finished 32%, Time = 70 / 150
Average Velocity = 45132718 thousands bars/sec.
Finished 33%, Time = 73 / 148
Average Velocity = 45142403 thousands bars/sec.
Finished 34%, Time = 75 / 146
Average Velocity = 45142530 thousands bars/sec.
Finished 35%, Time = 77 / 144
Average Velocity = 45133336 thousands bars/sec.
Finished 36%, Time = 79 / 141
Average Velocity = 45142764 thousands bars/sec.
Finished 37%, Time = 81 / 139
Average Velocity = 45151134 thousands bars/sec.
Finished 38%, Time = 84 / 137
Average Velocity = 45151018 thousands bars/sec.
Finished 39%, Time = 86 / 135
Average Velocity = 45158750 thousands bars/sec.
Finished 40%, Time = 88 / 132
Average Velocity = 45150294 thousands bars/sec.
Finished 41%, Time = 90 / 130
Average Velocity = 45142750 thousands bars/sec.
Finished 42%, Time = 93 / 128
Average Velocity = 45150124 thousands bars/sec.
Finished 43%, Time = 95 / 126
Average Velocity = 45157157 thousands bars/sec.
Finished 44%, Time = 97 / 123
Average Velocity = 45164336 thousands bars/sec.
Finished 45%, Time = 99 / 121
Average Velocity = 45163945 thousands bars/sec.
Finished 46%, Time = 101 / 119
Average Velocity = 45170223 thousands bars/sec.
Finished 47%, Time = 104 / 117
Average Velocity = 45176235 thousands bars/sec.
Finished 48%, Time = 106 / 115
Average Velocity = 45182424 thousands bars/sec.
Finished 49%, Time = 108 / 112
Average Velocity = 45187945 thousands bars/sec.
Finished 50%, Time = 110 / 110
Average Velocity = 45193654 thousands bars/sec.
Finished 51%, Time = 112 / 108
Average Velocity = 45192333 thousands bars/sec.
Finished 52%, Time = 115 / 106
Average Velocity = 45197740 thousands bars/sec.
Finished 53%, Time = 117 / 103
Average Velocity = 45202558 thousands bars/sec.
Finished 54%, Time = 119 / 101
Average Velocity = 45213255 thousands bars/sec.
Finished 55%, Time = 121 / 99
Average Velocity = 45217620 thousands bars/sec.
Finished 56%, Time = 123 / 97
Average Velocity = 45222194 thousands bars/sec.
Finished 57%, Time = 126 / 95
Average Velocity = 45226250 thousands bars/sec.
Finished 58%, Time = 128 / 92
Average Velocity = 45235811 thousands bars/sec.
Finished 59%, Time = 130 / 90
Average Velocity = 45239847 thousands bars/sec.
Finished 60%, Time = 132 / 88
Average Velocity = 45243409 thousands bars/sec.
Finished 61%, Time = 134 / 86
Average Velocity = 45252225 thousands bars/sec.
Finished 62%, Time = 137 / 83
Average Velocity = 45255474 thousands bars/sec.
Finished 63%, Time = 139 / 81
Average Velocity = 45258945 thousands bars/sec.
Finished 64%, Time = 141 / 79
Average Velocity = 45261989 thousands bars/sec.
Finished 65%, Time = 143 / 77
Average Velocity = 45269983 thousands bars/sec.
Finished 66%, Time = 145 / 75
Average Velocity = 45272768 thousands bars/sec.
Finished 67%, Time = 147 / 72
Average Velocity = 45275776 thousands bars/sec.
Finished 68%, Time = 150 / 70
Average Velocity = 45278395 thousands bars/sec.
Finished 69%, Time = 152 / 68
Average Velocity = 45281235 thousands bars/sec.
Finished 70%, Time = 154 / 66
Average Velocity = 45283702 thousands bars/sec.
Finished 71%, Time = 156 / 64
Average Velocity = 45286099 thousands bars/sec.
Finished 72%, Time = 158 / 61
Average Velocity = 45288715 thousands bars/sec.
Finished 73%, Time = 161 / 59
Average Velocity = 45290979 thousands bars/sec.
Finished 74%, Time = 163 / 57
Average Velocity = 45297617 thousands bars/sec.
Finished 75%, Time = 165 / 55
Average Velocity = 45295599 thousands bars/sec.
Finished 76%, Time = 167 / 52
Average Velocity = 45302003 thousands bars/sec.
Finished 77%, Time = 169 / 50
Average Velocity = 45299980 thousands bars/sec.
Finished 78%, Time = 172 / 48
Average Velocity = 45301954 thousands bars/sec.
Finished 79%, Time = 174 / 46
Average Velocity = 45308037 thousands bars/sec.
Finished 80%, Time = 176 / 44
Average Velocity = 45309862 thousands bars/sec.
Finished 81%, Time = 178 / 41
Average Velocity = 45311896 thousands bars/sec.
Finished 82%, Time = 180 / 39
Average Velocity = 45309875 thousands bars/sec.
Finished 83%, Time = 183 / 37
Average Velocity = 45307655 thousands bars/sec.
Finished 84%, Time = 185 / 35
Average Velocity = 45309642 thousands bars/sec.
Finished 85%, Time = 187 / 33
Average Velocity = 45307719 thousands bars/sec.
Finished 86%, Time = 189 / 30
Average Velocity = 45305602 thousands bars/sec.
Finished 87%, Time = 192 / 28
Average Velocity = 45300231 thousands bars/sec.
Finished 88%, Time = 194 / 26
Average Velocity = 45301978 thousands bars/sec.
Finished 89%, Time = 196 / 24
Average Velocity = 45303687 thousands bars/sec.
Finished 90%, Time = 198 / 22
Average Velocity = 45294869 thousands bars/sec.
Finished 91%, Time = 200 / 19
Average Velocity = 45296618 thousands bars/sec.
Finished 92%, Time = 203 / 17
Average Velocity = 45298551 thousands bars/sec.
Finished 93%, Time = 205 / 15
Average Velocity = 45296914 thousands bars/sec.
Finished 94%, Time = 207 / 13
Average Velocity = 45298585 thousands bars/sec.
Finished 95%, Time = 209 / 11
Average Velocity = 45300221 thousands bars/sec.
Finished 96%, Time = 211 / 8
Average Velocity = 45302037 thousands bars/sec.
Finished 97%, Time = 214 / 6
Average Velocity = 45303604 thousands bars/sec.
Finished 98%, Time = 216 / 4
Average Velocity = 45305139 thousands bars/sec.
Finished 99%, Time = 218 / 2
Average Velocity = 45303533 thousands bars/sec.


Т.е. у меня замедление, а у вас наоборот — ускорение.

Но самое странное, когда (чтобы не перепутать случаи) добавил эти строчки:

int main(int argc, char* argv[])
{
//  unsigned long int CalcBars = 0, CurrentBar = 100;
// Замена на эту строчку замедляет выполнение программы на ~ 15%.
  unsigned long long CalcBars = 0, CurrentBar = 100;

  std::cout << "SizeOf(Type) = " << sizeof(unsigned long long) << " bytes." << std::endl; // добавил
  std::cout << "SizeOf(CalcBars) = " << sizeof(&CalcBars) << " bytes." << std::endl; // добавил
  
  for (long long i = 0; i < AMOUNT; i++)
  .....

Результат стал таким:
SizeOf(Type) = 8 bytes.
SizeOf(CalcBars) = 4 bytes.
Finished 1%, Time = 4 / 489
Average Velocity = 20222446 th
Finished 2%, Time = 9 / 485
Average Velocity = 20189783 th
Finished 3%, Time = 14 / 480
...

Т.е. замедлилось еще в > 2 раза. Да еще и sizeof переменной показывает 4 байта, вместо 8-ми.

Попробовал на удаленной машине запустить — аналогично.

Помогите разобраться, почему этот бред происходит?!
Re[6]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 19:18
Оценка:
G>Т.е. замедлилось еще в > 2 раза. Да еще и sizeof переменной показывает 4 байта, вместо 8-ми.
Здесь я ступил, sizeof правильно отработал. Однако, объяснить такое доп. замедление не в состоянии.
Re: Замена типа переменной long int на long long без вычислений замедляет код на
От: VladFein США  
Дата: 30.08.13 19:28
Оценка:
Здравствуйте, getch, Вы писали:

G>Короткий пример...


При смене типа, декларацию функции Print() не поправляли?
Re[2]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 19:32
Оценка:
VF>При смене типа, декларацию функции Print() не поправляли?
Пробовал с/без соответствующей поправкой — на скорости выполнения не сказывается.
Re[3]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 19:47
Оценка:
Попробовал еще одну абсурдную идею. Если так написать:

  if (CalcBars < CalcBars) 
  {
    std::cout << "SizeOf(Type) = " << sizeof(unsigned long long) << " bytes." << std::endl;
    std::cout << "SizeOf(CalcBars) = " << sizeof(CalcBars) << " bytes." << std::endl;
  }


так же происходит замедление в > 2 раза.
Re[3]: Замена типа переменной long int на long long без вычислений замедляет код
От: VladFein США  
Дата: 30.08.13 20:07
Оценка:
Здравствуйте, getch, Вы писали:

G>Пробовал с/без соответствующей поправкой — на скорости выполнения не сказывается.


А если убрать опцию /fp:precise ?
Моя идея — что float инструкции смешиваются с long long арифметикой, и в 32-битной системе происходит какое-то дорогое переключение.
У меня 64-бит, Ваш результат не повторяется.
Re[4]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 20:21
Оценка:
VF>А если убрать опцию /fp:precise ?
Изменил на /fp:fast. Каждый случай стал немного быстрее, но между ними все равно пропасть по производительности.

VF>У меня 64-бит, Ваш результат не повторяется.

Visual Studio Ultimate предлагает только Win32 конфигурацию. Win64 в VS отсутствует, хоть OS x64.

Как получить Win64 конфигурацию?
Re[5]: Замена типа переменной long int на long long без вычислений замедляет код
От: VladFein США  
Дата: 30.08.13 20:25
Оценка:
Здравствуйте, getch, Вы писали:

G>Как получить Win64 конфигурацию?


В окне с конфигурацией х64, кликните "Configuration manager...", потом в "Active solution platform:" — <New...>
Re[6]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 20:36
Оценка:
VF>В окне с конфигурацией х64, кликните "Configuration manager...", потом в "Active solution platform:" — <New...>
Спасибо, переключился на x64-конфигурацию. Оба варианты стали выполняться с одинаковой производительностью. Но медленнее Win32-конфигурации на 40%.

При этом проблема
G>Попробовал еще одну абсурдную идею. Если так написать:

G>
G>  if (CalcBars < CalcBars) 
G>  {
G>    std::cout << "SizeOf(Type) = " << sizeof(unsigned long long) << " bytes." << std::endl;
G>    std::cout << "SizeOf(CalcBars) = " << sizeof(CalcBars) << " bytes." << std::endl;
G>  }
G>


G>так же происходит замедление в > 2 раза.


осталась актуальной.

Не хотелось бы останавливаться на медленном Win64-варианте, т.к. все таки речь не о программировании ради программирования, а о решении практической задачи — для него нужна хорошая производительность.

Могли бы вы попробовать у себя Win32-конфигурацию представленного кода?
Re[7]: Замена типа переменной long int на long long без вычислений замедляет код
От: VladFein США  
Дата: 30.08.13 22:01
Оценка:
Здравствуйте, getch, Вы писали:

G>Могли бы вы попробовать у себя Win32-конфигурацию представленного кода?


Пробую, но получается порядочный разброс: long int тест взял 616 и 674 секунды (!) на двух прогонах.
Машина слабенькая (ядер-то 12, но всего 2GH).
Попробую ещё во вторник.
А на укороченном тесте у Вас такая же разница? Может, срезать раз в 10?
Re[8]: Замена типа переменной long int на long long без вычислений замедляет код
От: getch  
Дата: 30.08.13 22:10
Оценка:
VF>А на укороченном тесте у Вас такая же разница? Может, срезать раз в 10?
Срезал в 10 раз. Соответствено, длительность выполнения любого варианта стала ровно в 10 раз короче.
Относительная разница в скоростях осталась попрежнему той же (и необъяснимой).
Re: Замена типа переменной long int на long long без вычислений замедляет код на
От: Kubyshev Andrey  
Дата: 31.08.13 06:43
Оценка:
Давай уже генери asm код и показывай что там такое!
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.