LINUX.ORG.RU

Сообщения Black_Penguin

 

VC6.0 vs GCC 3.4.0

Всем известно, что компиляторы от MS оптимизируют код значительно лучше, чем gcc. Так думал и я до вчерашнего вечера... Вот результаты тестов одной маленькой программки для нахождения простых чисел:

1. Offtopic 2000, VC6.0 оптимизация на скорость, athlon xp 1700, 128M RAM, nice realtime - время выполнения 105 сек.

2. Linux mdk 10.0, gcc 3.4.0 -march=athlon -O3, комп тот же, nice 0 - время выполнения 62 сек (!).

И где хваленое качество кода? Или я чего то не понимаю? Текст программы: /*************************************************************************** * Copyright (C) 2004 by Kostya * * smcr@mail.ru * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/

#include <iostream> #include <cstdlib> #include <time.h> using namespace std;

int main(int argc, char *argv[]) { const unsigned int a( 4000000000UL ),b( (unsigned int)(4001111000UL) ); const unsigned int lb( ((a/3)*3)+4 ),hb( b ); unsigned int o(0),i(0),t(0),simps(0); time_t s,e;

time(&s); for (o=lb;o<hb;o+=2){ i=5; while ( (o%i) && (i<(t=o/i)) ) i+=2; if(i>=t) simps++; o+=4; i=5; while ( (o%i) && (i<(t=o/i)) ) i+=2; if(i>=t) simps++; } time(&e); cout << endl << simps << endl << lb << endl << hb << endl << e-s; return EXIT_SUCCESS; }

Black_Penguin
()

RSS подписка на новые темы