X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f From: Alex Vinokur Newsgroups: comp.software.measurement,comp.lang.c++,comp.os.msdos.djgpp,comp.games.development.programming.misc Subject: Re: C/C++ Program Perfometer Date: Mon, 11 Mar 2002 09:49:50 +0200 Lines: 315 Message-ID: <3C8C619E.D3F557D5@bigfoot.com> References: <3C848503 DOT AB2A4938 AT bigfoot DOT com> <3C84CF9B DOT AA99EFA8 AT bigfoot DOT com> NNTP-Posting-Host: 62.90.123.5 Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1015832930 14813115 62.90.123.5 (16 [79865]) X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Performance of accesses to elements in C-array, STL vector, STL basic_string was measured when using C/C++ Program Perfometer at http://groups.google.com/groups?selm=3C84CF9B.AA99EFA8%40bigfoot.com . =============================================================== gpp : GNU C++ version 2.95.3 20010315/djgpp (release) (djgpp) compiled by GNU C version 2.95.3 20010315/djgpp (release). --------- Windows98 =============================================================== --- No optimization --- #========================================================== # Comparison Group#1 of 1 : access to array, vector, string #---------------------------------------------------------- # Resource Name : user time used # Resource Cost Unit : uclock # Resource State Unit : uclock #========================================================== : ------------------------------------------------------------------- : f1 : demo2.c #50 : operator[] - int array[100] -> 109 : f1 : demo2.c #63 : operator[] - int array[1000] -> 109 : f1 : demo2.c #77 : operator[] - int vector[100] -> 694 : f1 : demo2.c #91 : operator[] - int vector[1000] -> 710 : f1 : demo2.c #105 : operator[] - int string[100] -> 2959 : f1 : demo2.c #119 : operator[] - int string[1000] -> 2970 : f1 : demo2.c #133 : method at() - int string[100] -> 3865 : f1 : demo2.c #147 : method at() - int string[1000] -> 3866 : ------------------------------------------------------------------- --- Optimization O1 --- #========================================================== # Comparison Group#1 of 1 : access to array, vector, string #---------------------------------------------------------- # Resource Name : user time used # Resource Cost Unit : uclock # Resource State Unit : uclock #========================================================== : ------------------------------------------------------------------- : f1 : demo2.c #50 : operator[] - int array[100] -> 44 : f1 : demo2.c #63 : operator[] - int array[1000] -> 44 : f1 : demo2.c #77 : operator[] - int vector[100] -> 44 : f1 : demo2.c #91 : operator[] - int vector[1000] -> 44 : f1 : demo2.c #105 : operator[] - int string[100] -> 131 : f1 : demo2.c #119 : operator[] - int string[1000] -> 131 : f1 : demo2.c #133 : method at() - int string[100] -> 174 : f1 : demo2.c #147 : method at() - int string[1000] -> 174 : ------------------------------------------------------------------- --- Optimization O2 --- #========================================================== # Comparison Group#1 of 1 : access to array, vector, string #---------------------------------------------------------- # Resource Name : user time used # Resource Cost Unit : uclock # Resource State Unit : uclock #========================================================== : ------------------------------------------------------------------- : f1 : demo2.c #50 : operator[] - int array[100] -> 44 : f1 : demo2.c #63 : operator[] - int array[1000] -> 44 : f1 : demo2.c #77 : operator[] - int vector[100] -> 44 : f1 : demo2.c #91 : operator[] - int vector[1000] -> 44 : f1 : demo2.c #105 : operator[] - int string[100] -> 109 : f1 : demo2.c #119 : operator[] - int string[1000] -> 109 : f1 : demo2.c #133 : method at() - int string[100] -> 153 : f1 : demo2.c #147 : method at() - int string[1000] -> 153 : ------------------------------------------------------------------- --- Optimization O3 --- #========================================================== # Comparison Group#1 of 1 : access to array, vector, string #---------------------------------------------------------- # Resource Name : user time used # Resource Cost Unit : uclock # Resource State Unit : uclock #========================================================== : ------------------------------------------------------------------- : f1 : demo2.c #50 : operator[] - int array[100] -> 44 : f1 : demo2.c #63 : operator[] - int array[1000] -> 44 : f1 : demo2.c #77 : operator[] - int vector[100] -> 44 : f1 : demo2.c #91 : operator[] - int vector[1000] -> 44 : f1 : demo2.c #105 : operator[] - int string[100] -> 109 : f1 : demo2.c #119 : operator[] - int string[1000] -> 109 : f1 : demo2.c #133 : method at() - int string[100] -> 153 : f1 : demo2.c #147 : method at() - int string[1000] -> 153 : ------------------------------------------------------------------- // =================== File demo.h : BEGIN ==================== #ifndef _DEMO_H #define _DEMO_H #include "adapt.h" void f1 (void); #endif // =================== File demo.h : END ====================== // =================== File demo.c : BEGIN ==================== #include "demo.h" void SetEnvIt () { SetTotalTests (25); SetScaleAndTotalIterations (10000, 100000); } void MeasureIt () { } void CompareIt () { CompareFunc ("access to array, vector, string", f1); } // =================== File demo.c : END ====================== // =================== File demo2.c : BEGIN ==================== #include "demo.h" //--------------------------- #define TURN_ON_uclock(x) TURN_ON (uclock_t, uclock_t, RESOURCE_user_time_used, x) //--------------------------- #define SIZE1 100 #define SIZE2 1000 // ========================== void f1 (void) { // ------ Preparation ------ ostringstream osstr; const size_t median_index1 = SIZE1/2; const size_t median_index2 = SIZE2/2; int int_array1 [SIZE1]; int int_array2 [SIZE2]; for (size_t i = 0; i < SIZE1; i++) int_array1[i] = 10*i; for (size_t i = 0; i < SIZE2; i++) int_array2[i] = 10*i; vector int_vector1 (int_array1, int_array1 + sizeof(int_array1)/sizeof(int_array1[0])); vector int_vector2 (int_array2, int_array2 + sizeof(int_array2)/sizeof(int_array2[0])); assert (int_vector1.size() == (sizeof(int_array1)/sizeof(int_array1[0]))); assert (int_vector2.size() == (sizeof(int_array2)/sizeof(int_array2[0]))); assert (median_index1 < int_vector1.size()); assert (median_index2 < int_vector2.size()); basic_string int_string1 ((sizeof(int_array1)/sizeof(int_array1[0])), 111); basic_string int_string2 ((sizeof(int_array2)/sizeof(int_array2[0])), 222); assert (int_string1.size() == (sizeof(int_array1)/sizeof(int_array1[0]))); assert (int_string2.size() == (sizeof(int_array2)/sizeof(int_array2[0]))); assert (median_index1 < int_string1.size()); assert (median_index2 < int_string2.size()); // -------- [] : int_array1 [100] -------- { osstr.str(string()); osstr << "operator[] - int array[" << (sizeof(int_array1)/sizeof(int_array1[0])) << "]"; TURN_ON_uclock(osstr.str()) { int_array1 [median_index1]; } } // -------- [] :int_array2 [1000] -------- { osstr.str(string()); osstr << "operator[] - int array[" << (sizeof(int_array2)/sizeof(int_array2[0])) << "]"; TURN_ON_uclock(osstr.str()) { int_array2 [median_index2]; } } // -------- [] : int_vector1 [100] -------- { osstr.str(string()); osstr << "operator[] - int vector[" << int_vector1.size() << "]"; TURN_ON_uclock(osstr.str()) { int_vector1 [median_index1]; } } // -------- [] : int_vector2 [1000] -------- { osstr.str(string()); osstr << "operator[] - int vector[" << int_vector2.size() << "]"; TURN_ON_uclock(osstr.str()) { int_vector2 [median_index2]; } } // -------- [] : int_string1 [100] -------- { osstr.str(string()); osstr << "operator[] - int string[" << int_string1.size() << "]"; TURN_ON_uclock(osstr.str()) { int_string1 [median_index1]; } } // -------- [] : int_string2 [1000] -------- { osstr.str(string()); osstr << "operator[] - int string[" << int_string2.size() << "]"; TURN_ON_uclock(osstr.str()) { int_string2 [median_index2]; } } // -------- at() : int_string1 [100] -------- { osstr.str(string()); osstr << "method at() - int string[" << int_string1.size() << "]"; TURN_ON_uclock(osstr.str()) { int_string1.at(median_index1); } } // -------- at() : int_string2 [1000] -------- { osstr.str(string()); osstr << "method at() - int string[" << int_string2.size() << "]"; TURN_ON_uclock(osstr.str()) { int_string2.at(median_index2); } } } // f1 // =================== File demo2.c : END ====================== =========================== Alex Vinokur mailto:alexvn AT bigfoot DOT com mailto:alexvn AT go DOT to http://up.to/alexvn http://go.to/alexv_math ===========================