Anybody may help to explain the issue of the source code , next "try-throw-catch" will cost more cpu time than previous one

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,
I test some code and I found that "next 'try-throw-catch' will cost more cpu time than previous one". Could you help to explain this case !! 

Thanks a lot !

Miles Zhao

the result is follow :
start0:1224705604
end  0:1224705613
totle0:9
******************
start1:1224705613
end  1:1224705624
totle1:11
******************
start2:1224705624
end  2:1224705636
totle2:12
******************
start3:1224705636
end  3:1224705649
totle3:13
******************
start0:1224705649
end  0:1224705659
totle0:10
******************
start1:1224705659
end  1:1224705670
totle1:11
******************
start2:1224705670
end  2:1224705682
totle2:12
******************
start3:1224705682
end  3:1224705694
totle3:12
******************
....



My environmount is :
system : CentOS release 5.2 (Final)
gcc info: Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)

and the test code is :

#include <iostream>
#include <sys/time.h>
#include <time.h>

using std::string;

#define COUNT 0x2fffff


#define GET_TIME                                                        \
        do{                                                             \
                gettimeofday( &tm_val , NULL );                         \
        }while(0)

#define SET_TIME( SECOND )                                              \
{                                                                       \
        GET_TIME;                                                       \
        (SECOND) = tm_val.tv_sec;                                       \
}

#define  TEST_ROUTINE( num )                                            \
{                                                                       \
        i=0;                                                            \
                                                                        \
        SET_TIME( start_time );                                         \
        std::cout <<"start" <<num << ":" << start_time  <<std::endl;    \
                                                                        \
        while(i != COUNT ){                                             \
                try{                                                    \
                        throw string( "this is a throw out exception"); \
                                                                        \
                }catch( string excp ){                                  \
                        string excps = excp;                            \
                }                                                       \
                i++;                                                    \
        }                                                               \
                                                                        \
        SET_TIME( end_time );                                           \
        std::cout << "end  " <<num << ":" << end_time <<std::endl;      \
        std::cout << "totle" <<num << ":" << end_time - start_time << std::endl;        \
        std::cout << "******************"<<std::endl;                   \
}

int main(){

        unsigned int i;
        struct timeval tm_val;
        time_t start_time , end_time;

        while(1){

                TEST_ROUTINE(0);
                TEST_ROUTINE(1);
                TEST_ROUTINE(2);
                TEST_ROUTINE(3);
        }
                TEST_ROUTINE(4);
                TEST_ROUTINE(5);
                TEST_ROUTINE(6);
                TEST_ROUTINE(7);
                TEST_ROUTINE(8);
                TEST_ROUTINE(9);


        return 0;
}



      ___________________________________________________________ 
  好玩贺卡等你发,邮箱贺卡全新上线! 
http://card.mail.cn.yahoo.com/


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux