Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Performance : calling templated and non-templated functions

0 views
Skip to first unread message

Alex Vinokur

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to

Hi,

Performance of calling
templated and non-templated functions
was measured.

1. Two data types were used : int and string
2. 4 optimization options of egcs compiler were used.


Average time-cost of execution was obtained.
The results of the experiment are shown below.

Thanks,
Alex


//########################################################
//------------------- C++ code : BEGIN -------------------

//=================================================
#include <string>
#include <sys/time.h>

//=======================
void print_status (
int testNo_i,
hrtime_t& t_start_i,
hrtime_t& t_end_i,
int iters_i,
const string& name_i
)
{
cout << "Test#"
<< testNo_i
<< " ["
<< name_i.c_str ()
<< "]"
<< "\t: "
<< "\tAverage time = "
<< ((t_end_i - t_start_i)/iters_i)
<< " nsec"
<< endl;
}
//=======================
#define PRINT(testNo_i, object_i) \
print_status ( \
testNo_i, \
time_start, \
time_end, \
TOTAL_Iterations, \
#object_i)

//####################################################
template <typename T>
void templated_foo (const T& t_i)
{
T t;
}

//----------------
void ordinary_foo (int t_i)
{
int t;
}

//----------------
void ordinary_foo (const string& t_i)
{
string t;
}


//####################################################
int main()
{
//=======================
const unsigned int TOTAL_Tests = 5;
const unsigned int TOTAL_Iterations = 10000;

//=======================
hrtime_t time_start;
hrtime_t time_end;
//=======================

unsigned int curTestNo;
unsigned int curIndex;
unsigned int curIteration;

for (curTestNo = 1;
curTestNo <= TOTAL_Tests;
curTestNo++)
{
//=======================
cout << endl
<< "\t"
<< "##### Test#"
<< curTestNo
<< " (functions)"
<< " #####"
<< endl;

//############ int #################
//=======================================
time_start = gethrtime();
for (curIteration = 1;
curIteration <= TOTAL_Iterations;
curIteration++)
{
templated_foo (123);
}
time_end = gethrtime();
PRINT (curTestNo, templated_foo_int_1);
//===============================

//############ int #################
//=======================================
time_start = gethrtime();
for (curIteration = 1;
curIteration <= TOTAL_Iterations;
curIteration++)
{
templated_foo<int> (123);
}
time_end = gethrtime();
PRINT (curTestNo, templated_foo_int_2);
//===============================

//############ int #################
//=======================================
time_start = gethrtime();
for (curIteration = 1;
curIteration <= TOTAL_Iterations;
curIteration++)
{
ordinary_foo (123);
}
time_end = gethrtime();
PRINT (curTestNo, ordinary_foo_int);
//===============================

string s123 ("123");
//############ string #################
//=======================================
time_start = gethrtime();
for (curIteration = 1;
curIteration <= TOTAL_Iterations;
curIteration++)
{
templated_foo (s123);
}
time_end = gethrtime();
PRINT (curTestNo, templated_foo_string_1);
//===============================

//############ string #################
//=======================================
time_start = gethrtime();
for (curIteration = 1;
curIteration <= TOTAL_Iterations;
curIteration++)
{
templated_foo<string> (s123);
}
time_end = gethrtime();
PRINT (curTestNo, templated_foo_string_2);
//===============================

//############ string #################
//=======================================
time_start = gethrtime();
for (curIteration = 1;
curIteration <= TOTAL_Iterations;
curIteration++)
{
ordinary_foo (s123);
}
time_end = gethrtime();
PRINT (curTestNo, ordinary_foo_string);
//===============================

} // for (curTestNo = 1; curTestNo <= TOTAL_Tests; curTestNo++)
//======================
return 0;
}

//------------------- C++ code : END ---------------------

//#########################################################
//------------------- Running Results : BEGIN -------------

//--------------------------
% g++ perf.C
% a.out

##### Test#1 (functions) #####
Test#1 [templated_foo_int_1] : Average time = 249 nsec
Test#1 [templated_foo_int_2] : Average time = 211 nsec
Test#1 [ordinary_foo_int] : Average time = 163 nsec
Test#1 [templated_foo_string_1] : Average time = 1435 nsec
Test#1 [templated_foo_string_2] : Average time = 5222 nsec
Test#1 [ordinary_foo_string] : Average time = 692 nsec

##### Test#2 (functions) #####
Test#2 [templated_foo_int_1] : Average time = 212 nsec
Test#2 [templated_foo_int_2] : Average time = 191 nsec
Test#2 [ordinary_foo_int] : Average time = 163 nsec
Test#2 [templated_foo_string_1] : Average time = 1294 nsec
Test#2 [templated_foo_string_2] : Average time = 1216 nsec
Test#2 [ordinary_foo_string] : Average time = 593 nsec

##### Test#3 (functions) #####
Test#3 [templated_foo_int_1] : Average time = 191 nsec
Test#3 [templated_foo_int_2] : Average time = 221 nsec
Test#3 [ordinary_foo_int] : Average time = 163 nsec
Test#3 [templated_foo_string_1] : Average time = 1215 nsec
Test#3 [templated_foo_string_2] : Average time = 1238 nsec
Test#3 [ordinary_foo_string] : Average time = 555 nsec

##### Test#4 (functions) #####
Test#4 [templated_foo_int_1] : Average time = 231 nsec
Test#4 [templated_foo_int_2] : Average time = 191 nsec
Test#4 [ordinary_foo_int] : Average time = 163 nsec
Test#4 [templated_foo_string_1] : Average time = 3664 nsec
Test#4 [templated_foo_string_2] : Average time = 2135 nsec
Test#4 [ordinary_foo_string] : Average time = 562 nsec

##### Test#5 (functions) #####
Test#5 [templated_foo_int_1] : Average time = 191 nsec
Test#5 [templated_foo_int_2] : Average time = 191 nsec
Test#5 [ordinary_foo_int] : Average time = 170 nsec
Test#5 [templated_foo_string_1] : Average time = 1222 nsec
Test#5 [templated_foo_string_2] : Average time = 1204 nsec
Test#5 [ordinary_foo_string] : Average time = 629 nsec
//--------------------------


//--------------------------
% g++ -O1 perf.C
% a.out

##### Test#1 (functions) #####
Test#1 [templated_foo_int_1] : Average time = 92 nsec
Test#1 [templated_foo_int_2] : Average time = 92 nsec
Test#1 [ordinary_foo_int] : Average time = 72 nsec
Test#1 [templated_foo_string_1] : Average time = 457 nsec
Test#1 [templated_foo_string_2] : Average time = 255 nsec
Test#1 [ordinary_foo_string] : Average time = 254 nsec

##### Test#2 (functions) #####
Test#2 [templated_foo_int_1] : Average time = 185 nsec
Test#2 [templated_foo_int_2] : Average time = 92 nsec
Test#2 [ordinary_foo_int] : Average time = 138 nsec
Test#2 [templated_foo_string_1] : Average time = 255 nsec
Test#2 [templated_foo_string_2] : Average time = 270 nsec
Test#2 [ordinary_foo_string] : Average time = 255 nsec

##### Test#3 (functions) #####
Test#3 [templated_foo_int_1] : Average time = 92 nsec
Test#3 [templated_foo_int_2] : Average time = 92 nsec
Test#3 [ordinary_foo_int] : Average time = 631 nsec
Test#3 [templated_foo_string_1] : Average time = 269 nsec
Test#3 [templated_foo_string_2] : Average time = 254 nsec
Test#3 [ordinary_foo_string] : Average time = 254 nsec

##### Test#4 (functions) #####
Test#4 [templated_foo_int_1] : Average time = 92 nsec
Test#4 [templated_foo_int_2] : Average time = 98 nsec
Test#4 [ordinary_foo_int] : Average time = 72 nsec
Test#4 [templated_foo_string_1] : Average time = 254 nsec
Test#4 [templated_foo_string_2] : Average time = 254 nsec
Test#4 [ordinary_foo_string] : Average time = 261 nsec

##### Test#5 (functions) #####
Test#5 [templated_foo_int_1] : Average time = 92 nsec
Test#5 [templated_foo_int_2] : Average time = 92 nsec
Test#5 [ordinary_foo_int] : Average time = 72 nsec
Test#5 [templated_foo_string_1] : Average time = 281 nsec
Test#5 [templated_foo_string_2] : Average time = 254 nsec
Test#5 [ordinary_foo_string] : Average time = 254 nsec
//--------------------------

//--------------------------
% g++ -O2 perf.C
% a.out

##### Test#1 (functions) #####
Test#1 [templated_foo_int_1] : Average time = 92 nsec
Test#1 [templated_foo_int_2] : Average time = 73 nsec
Test#1 [ordinary_foo_int] : Average time = 72 nsec
Test#1 [templated_foo_string_1] : Average time = 482 nsec
Test#1 [templated_foo_string_2] : Average time = 303 nsec
Test#1 [ordinary_foo_string] : Average time = 303 nsec

##### Test#2 (functions) #####
Test#2 [templated_foo_int_1] : Average time = 125 nsec
Test#2 [templated_foo_int_2] : Average time = 73 nsec
Test#2 [ordinary_foo_int] : Average time = 72 nsec
Test#2 [templated_foo_string_1] : Average time = 303 nsec
Test#2 [templated_foo_string_2] : Average time = 310 nsec
Test#2 [ordinary_foo_string] : Average time = 303 nsec

##### Test#3 (functions) #####
Test#3 [templated_foo_int_1] : Average time = 73 nsec
Test#3 [templated_foo_int_2] : Average time = 73 nsec
Test#3 [ordinary_foo_int] : Average time = 191 nsec
Test#3 [templated_foo_string_1] : Average time = 303 nsec
Test#3 [templated_foo_string_2] : Average time = 303 nsec
Test#3 [ordinary_foo_string] : Average time = 303 nsec

##### Test#4 (functions) #####
Test#4 [templated_foo_int_1] : Average time = 73 nsec
Test#4 [templated_foo_int_2] : Average time = 73 nsec
Test#4 [ordinary_foo_int] : Average time = 72 nsec
Test#4 [templated_foo_string_1] : Average time = 310 nsec
Test#4 [templated_foo_string_2] : Average time = 303 nsec
Test#4 [ordinary_foo_string] : Average time = 310 nsec

##### Test#5 (functions) #####
Test#5 [templated_foo_int_1] : Average time = 73 nsec
Test#5 [templated_foo_int_2] : Average time = 73 nsec
Test#5 [ordinary_foo_int] : Average time = 72 nsec
Test#5 [templated_foo_string_1] : Average time = 303 nsec
Test#5 [templated_foo_string_2] : Average time = 323 nsec
Test#5 [ordinary_foo_string] : Average time = 303 nsec
//--------------------------

//--------------------------
% g++ -O3 perf.C
% a.out

##### Test#1 (functions) #####
Test#1 [templated_foo_int_1] : Average time = 92 nsec
Test#1 [templated_foo_int_2] : Average time = 92 nsec
Test#1 [ordinary_foo_int] : Average time = 18 nsec
Test#1 [templated_foo_string_1] : Average time = 227 nsec
Test#1 [templated_foo_string_2] : Average time = 227 nsec
Test#1 [ordinary_foo_string] : Average time = 457 nsec

##### Test#2 (functions) #####
Test#2 [templated_foo_int_1] : Average time = 92 nsec
Test#2 [templated_foo_int_2] : Average time = 92 nsec
Test#2 [ordinary_foo_int] : Average time = 18 nsec
Test#2 [templated_foo_string_1] : Average time = 302 nsec
Test#2 [templated_foo_string_2] : Average time = 302 nsec
Test#2 [ordinary_foo_string] : Average time = 309 nsec

##### Test#3 (functions) #####
Test#3 [templated_foo_int_1] : Average time = 92 nsec
Test#3 [templated_foo_int_2] : Average time = 92 nsec
Test#3 [ordinary_foo_int] : Average time = 18 nsec
Test#3 [templated_foo_string_1] : Average time = 302 nsec
Test#3 [templated_foo_string_2] : Average time = 302 nsec
Test#3 [ordinary_foo_string] : Average time = 317 nsec

##### Test#4 (functions) #####
Test#4 [templated_foo_int_1] : Average time = 92 nsec
Test#4 [templated_foo_int_2] : Average time = 105 nsec
Test#4 [ordinary_foo_int] : Average time = 25 nsec
Test#4 [templated_foo_string_1] : Average time = 302 nsec
Test#4 [templated_foo_string_2] : Average time = 314 nsec
Test#4 [ordinary_foo_string] : Average time = 434 nsec

##### Test#5 (functions) #####
Test#5 [templated_foo_int_1] : Average time = 92 nsec
Test#5 [templated_foo_int_2] : Average time = 91 nsec
Test#5 [ordinary_foo_int] : Average time = 18 nsec
Test#5 [templated_foo_string_1] : Average time = 302 nsec
Test#5 [templated_foo_string_2] : Average time = 318 nsec
Test#5 [ordinary_foo_string] : Average time = 319 nsec
//--------------------------

//------------------- Running Results : END ---------------


//#########################################################
//------------------- Compiler & System ------------------

g++ -v : gcc version egcs-2.91.57 19980901
(egcs-1.1 release)

uname -a : SunOS <nodename> 5.6 Generic_105181-09
sun4m sparc SUNW,SPARCstation-5

psrinfo -v : -> The sparc processor operates at 110 MHz

//---------------------------------------------------------

//#########################################################


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Pablo

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to
And your point is?

Pablo

Alex Vinokur wrote in message <7njovc$p17$1...@nnrp1.deja.com>...

Greg Comeau

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to
In article <7njovc$p17$1...@nnrp1.deja.com> Alex Vinokur <alexande...@telrad.co.il> writes:
>Performance of calling
> templated and non-templated functions
> was measured.
>
>1. Two data types were used : int and string
>2. 4 optimization options of egcs compiler were used.
>
>
>Average time-cost of execution was obtained.
>The results of the experiment are shown below.

Two things seem to be stateable from those results:
a) _for this test_ things were about equal
(I suspect you did this on a UNIX box being used by others at
the same time given the time variances).
b) templated_foo and ordinary_foo were not the same function,
although it did not seem to matter except for the very last
optimization switch used.

- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C/C++ 4.2.38 -- New Release! We now do Windows too.
Email: com...@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
*** WEB: http://www.comeaucomputing.com ***

Miika Lappalainen

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Okay, now explain what causes the differences in results, if you can.
(This should be interesting)

Alex Vinokur

unread,
Jul 29, 1999, 3:00:00 AM7/29/99
to
In article <379EEFCD...@opcode.fi>,

Miika Lappalainen <miika.la...@opcode.fi> wrote:
> Okay, now explain what causes the differences in results, if you can.
> (This should be interesting)
>

Hi,

It is a question that I would like get answer as well.

The only conclusion (my conclusion) is :
1) if our program contains templated functions taking parameters of
"heavy" types (as string) and
2) if performace is critical factor
we need to use optimization options while compilation.

Alex.

Notes-questions.
1) If performace is a critical factor -> is it worth always using
optimization options while compilation?
Maybe it is preferable to improve algorithm (if we can); but it takes
time.
2) Are compilation options dangerous?

Alex

Greg Comeau

unread,
Jul 29, 1999, 3:00:00 AM7/29/99
to
In article <7noqbg$2m8$1...@nnrp1.deja.com> Alex Vinokur <alexande...@telrad.co.il> writes:
>In article <379EEFCD...@opcode.fi>,
> Miika Lappalainen <miika.la...@opcode.fi> wrote:
>> Okay, now explain what causes the differences in results, if you can.
>> (This should be interesting)
>
>It is a question that I would like get answer as well.
>
>The only conclusion (my conclusion) is :
>1) if our program contains templated functions taking parameters of
>"heavy" types (as string) and
>2) if performace is critical factor
>we need to use optimization options while compilation.

How could you draw those conclusion? As I recall,
you ran some 6 tests 5 times each. The times were the same
over the 5 times for either one. They only changed (for both)
when you optimized. Also, as previous mentioned, your
function template was not the same as the non-template version.

>Notes-questions.
>1) If performace is a critical factor -> is it worth always using
>optimization options while compilation?

Probably.

>Maybe it is preferable to improve algorithm (if we can); but it takes
>time.

That too.

>2) Are compilation options dangerous?

In some compilers they are. Read the documentation first
to see what the vendor says.

Alex Vinokur

unread,
Aug 1, 1999, 3:00:00 AM8/1/99
to
In article <7npvpb$aiv$1...@panix.com>,

com...@comeaucomputing.com wrote:
> In article <7noqbg$2m8$1...@nnrp1.deja.com> Alex Vinokur
<alexande...@telrad.co.il> writes:
[snip]

> >
> >The only conclusion (my conclusion) is :
> >1) if our program contains templated functions taking parameters of
> >"heavy" types (as string) and
> >2) if performace is critical factor
> >we need to use optimization options while compilation.
>
> How could you draw those conclusion? As I recall,
> you ran some 6 tests 5 times each. The times were the same
> over the 5 times for either one. They only changed (for both)
> when you optimized. Also, as previous mentioned, your
> function template was not the same as the non-template version.
>
[snip]

Hi,

If we don't use optimization option,
calling templated function (taking string parameter)
takes more time than calling non-templated one.

If we use optimization option the times are the same.

So, if we want to use such templated functions and
performance is critical factor
we need to use optimization options.

Thanks,
Alex

//--------------------------
% g++ perf.C // no optimization options
% a.out

##### Test#1 (functions) #####


Test#1 [templated_foo_string_1] : Average time = 1435 nsec
Test#1 [templated_foo_string_2] : Average time = 5222 nsec
Test#1 [ordinary_foo_string] : Average time = 692 nsec

##### Test#2 (functions) #####


Test#2 [templated_foo_string_1] : Average time = 1294 nsec
Test#2 [templated_foo_string_2] : Average time = 1216 nsec
Test#2 [ordinary_foo_string] : Average time = 593 nsec

##### Test#3 (functions) #####


Test#3 [templated_foo_string_1] : Average time = 1215 nsec
Test#3 [templated_foo_string_2] : Average time = 1238 nsec
Test#3 [ordinary_foo_string] : Average time = 555 nsec

##### Test#4 (functions) #####


Test#4 [templated_foo_string_1] : Average time = 3664 nsec
Test#4 [templated_foo_string_2] : Average time = 2135 nsec
Test#4 [ordinary_foo_string] : Average time = 562 nsec

##### Test#5 (functions) #####


Test#5 [templated_foo_string_1] : Average time = 1222 nsec
Test#5 [templated_foo_string_2] : Average time = 1204 nsec
Test#5 [ordinary_foo_string] : Average time = 629 nsec
//--------------------------

//--------------------------
% g++ -O1 perf.C
% a.out

##### Test#1 (functions) #####


Test#1 [templated_foo_string_1] : Average time = 457 nsec
Test#1 [templated_foo_string_2] : Average time = 255 nsec
Test#1 [ordinary_foo_string] : Average time = 254 nsec

##### Test#2 (functions) #####


Test#2 [templated_foo_string_1] : Average time = 255 nsec
Test#2 [templated_foo_string_2] : Average time = 270 nsec
Test#2 [ordinary_foo_string] : Average time = 255 nsec

##### Test#3 (functions) #####


Test#3 [templated_foo_string_1] : Average time = 269 nsec
Test#3 [templated_foo_string_2] : Average time = 254 nsec
Test#3 [ordinary_foo_string] : Average time = 254 nsec

##### Test#4 (functions) #####


Test#4 [templated_foo_string_1] : Average time = 254 nsec
Test#4 [templated_foo_string_2] : Average time = 254 nsec
Test#4 [ordinary_foo_string] : Average time = 261 nsec

##### Test#5 (functions) #####


Test#5 [templated_foo_string_1] : Average time = 281 nsec
Test#5 [templated_foo_string_2] : Average time = 254 nsec
Test#5 [ordinary_foo_string] : Average time = 254 nsec
//--------------------------

//--------------------------
% g++ -O2 perf.C
% a.out

##### Test#1 (functions) #####


Test#1 [templated_foo_string_1] : Average time = 482 nsec
Test#1 [templated_foo_string_2] : Average time = 303 nsec
Test#1 [ordinary_foo_string] : Average time = 303 nsec

##### Test#2 (functions) #####


Test#2 [templated_foo_string_1] : Average time = 303 nsec
Test#2 [templated_foo_string_2] : Average time = 310 nsec
Test#2 [ordinary_foo_string] : Average time = 303 nsec

##### Test#3 (functions) #####


Test#3 [templated_foo_string_1] : Average time = 303 nsec
Test#3 [templated_foo_string_2] : Average time = 303 nsec
Test#3 [ordinary_foo_string] : Average time = 303 nsec

##### Test#4 (functions) #####


Test#4 [templated_foo_string_1] : Average time = 310 nsec
Test#4 [templated_foo_string_2] : Average time = 303 nsec
Test#4 [ordinary_foo_string] : Average time = 310 nsec

##### Test#5 (functions) #####


Test#5 [templated_foo_string_1] : Average time = 303 nsec
Test#5 [templated_foo_string_2] : Average time = 323 nsec
Test#5 [ordinary_foo_string] : Average time = 303 nsec
//--------------------------

//--------------------------
% g++ -O3 perf.C
% a.out

##### Test#1 (functions) #####


Test#1 [templated_foo_string_1] : Average time = 227 nsec
Test#1 [templated_foo_string_2] : Average time = 227 nsec
Test#1 [ordinary_foo_string] : Average time = 457 nsec

##### Test#2 (functions) #####


Test#2 [templated_foo_string_1] : Average time = 302 nsec
Test#2 [templated_foo_string_2] : Average time = 302 nsec
Test#2 [ordinary_foo_string] : Average time = 309 nsec

##### Test#3 (functions) #####


Test#3 [templated_foo_string_1] : Average time = 302 nsec
Test#3 [templated_foo_string_2] : Average time = 302 nsec
Test#3 [ordinary_foo_string] : Average time = 317 nsec

##### Test#4 (functions) #####


Test#4 [templated_foo_string_1] : Average time = 302 nsec
Test#4 [templated_foo_string_2] : Average time = 314 nsec
Test#4 [ordinary_foo_string] : Average time = 434 nsec

##### Test#5 (functions) #####


Test#5 [templated_foo_string_1] : Average time = 302 nsec
Test#5 [templated_foo_string_2] : Average time = 318 nsec
Test#5 [ordinary_foo_string] : Average time = 319 nsec
//--------------------------

Sent via Deja.com http://www.deja.com/

blargg

unread,
Aug 1, 1999, 3:00:00 AM8/1/99
to
In article <7o0s8t$e9k$1...@nnrp1.deja.com>, Alex Vinokur
<alexande...@telrad.co.il> wrote:

Make it stopppppp!!!!!!!!!

Please!


Read up on testing performance.

Look at the disassembly for the versions. I imagine they will be exactly
the same for template and non-template functions (assuming your template
functions are the same as the non-template ones, which they don't seem to
be here), with or without optimizations.

Miika Lappalainen

unread,
Aug 2, 1999, 3:00:00 AM8/2/99
to

blargg wrote:
>
> Make it stopppppp!!!!!!!!!
>
> Please!
>
> Read up on testing performance.
>
> Look at the disassembly for the versions. I imagine they will be exactly
> the same for template and non-template functions (assuming your template
> functions are the same as the non-template ones, which they don't seem to
> be here), with or without optimizations.

Yes, they should be the same. The differences in result are most
probably because of the poor test functions, environment and too few
iterations. A fly landing on a table might have affected
those results.

Greg Comeau

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to

I think this draws the wrong conclusion. Certainly one test is
not conclusive.

The times of 5222 and 3664 are clearly out of whack. (BTW I raises this
and some other issue in a previous post but you did not respond on it).
This might indicate that they all are. Let's ignore that though.
That means the average templated version are some 2.5'ish
time slower. Did you find out why? If both the "ordinary"
and template version of the function both take a const string&
why would there be and difference? Is your compiler perhaps
throwing away 'string t;' but not 'T t;'? Is it inlining the
non-template one? What happens if you put the loop for the
ordinary_foo taking the string first? Etc, etc.

Alex Vinokur

unread,
Aug 4, 1999, 3:00:00 AM8/4/99
to
In article <7o78pf$jgl$1...@panix.com>,

com...@comeaucomputing.com wrote:
> In article <7o0s8t$e9k$1...@nnrp1.deja.com> Alex Vinokur
<alexande...@telrad.co.il> writes:
> >In article <7npvpb$aiv$1...@panix.com>,
> > com...@comeaucomputing.com wrote:
[snip]

> I think this draws the wrong conclusion. Certainly one test is
> not conclusive.
>
> The times of 5222 and 3664 are clearly out of whack. (BTW I raises
this
> and some other issue in a previous post but you did not respond on
it).

I believed I responded. Sorry, if I am mistaken.

> This might indicate that they all are. Let's ignore that though.
> That means the average templated version are some 2.5'ish
> time slower. Did you find out why?

I would like to do it.

> If both the "ordinary"
> and template version of the function both take a const string&
> why would there be and difference? Is your compiler perhaps
> throwing away 'string t;' but not 'T t;'? Is it inlining the
> non-template one? What happens if you put the loop for the
> ordinary_foo taking the string first? Etc, etc.
>

[snip]

Were any results gotten on your compiler?

Thanks,
Alex

Greg Comeau

unread,
Aug 4, 1999, 3:00:00 AM8/4/99
to
In article <7o8hio$njf$1...@nnrp1.deja.com> Alex Vinokur <alexande...@telrad.co.il> writes:
>In article <7o78pf$jgl$1...@panix.com>,

> com...@comeaucomputing.com wrote:
>> In article <7o0s8t$e9k$1...@nnrp1.deja.com> Alex Vinokur
><alexande...@telrad.co.il> writes:
>> >In article <7npvpb$aiv$1...@panix.com>,
>> > com...@comeaucomputing.com wrote:
>[snip]
>> I think this draws the wrong conclusion. Certainly one test is
>> not conclusive.
>>
>> The times of 5222 and 3664 are clearly out of whack. (BTW I raises
>this
>> and some other issue in a previous post but you did not respond on
>it).
>
>I believed I responded. Sorry, if I am mistaken.
>
>> This might indicate that they all are. Let's ignore that though.
>> That means the average templated version are some 2.5'ish
>> time slower. Did you find out why?
>
>I would like to do it.

Why no look at the generated code then?

>> If both the "ordinary"
>> and template version of the function both take a const string&
>> why would there be and difference? Is your compiler perhaps
>> throwing away 'string t;' but not 'T t;'? Is it inlining the
>> non-template one? What happens if you put the loop for the
>> ordinary_foo taking the string first? Etc, etc.
>>
>[snip]
>
>Were any results gotten on your compiler?

We _definitely_ generate the same code for the two functions,
so although I have not executed your code, I'm safe to say
that Comeau C++ will not have the 2.5 variance you showed for
the other compiler.

Vesa A J Karvonen

unread,
Aug 4, 1999, 3:00:00 AM8/4/99
to
In comp.lang.c++ Alex Vinokur <alexande...@telrad.co.il> wrote:
> Hi,

> Performance of calling
> templated and non-templated functions
> was measured.

> 1. Two data types were used : int and string
> 2. 4 optimization options of egcs compiler were used.

> Average time-cost of execution was obtained.
> The results of the experiment are shown below.

[snip]

Honestly, I'm not trying to insult, but your test is ridiculous. If you
are really interested in this kind of stuff, then you should learn an
assembly language or two and examine the compiler output for your test
code. You will find out that the compiler can inline functions even when
it is not explicitly told to do so. You will also find out that the
compiler can eliminate loops that do no work.

---
Vesa Karvonen

Alex Vinokur

unread,
Aug 17, 1999, 3:00:00 AM8/17/99
to
In article <7noqbg$2m8$1...@nnrp1.deja.com>,
Alex Vinokur <alexande...@telrad.co.il> wrote:
[snip]

> 1) If performace is a critical factor -> is it worth always using
> optimization options while compilation?
> Maybe it is preferable to improve algorithm (if we can); but it takes
> time.
> 2) Are compilation options dangerous?
[snip]

See the message titled "Deadly optimization bug (all versions!)"
in gnu.gcc.help
1999/08/16

http://www.deja.com/=dnc/[ST_rn=ps]/getdoc.xp?AN=513335200

Alex

Martin Ambuhl

unread,
Aug 17, 1999, 3:00:00 AM8/17/99
to

Alex Vinokur wrote:

> See the message titled "Deadly optimization bug (all versions!)"
> in gnu.gcc.help
> 1999/08/16
>
> http://www.deja.com/=dnc/[ST_rn=ps]/getdoc.xp?AN=513335200

Below is a more useful URL, I think. Watch out for newsreader-inserted
newlines. There are currently 7 messages in this thread, not one. The
original post (by Veksler Michael) has received several useful
responses, including 2 by the comp.lang.c regular Kaz Kylheku.


http://x24.deja.com/[ST_rn=if]/viewthread.xp?thitnum=0&mhitnum=0&toffset=0&CONTEXT=934920527.1225195580&frpage=threadmsg_if.xp&back=gnu.gcc.help&rok=1

This is highly implementation-specific, so strictly speaking off-topic
in alt.comp.lang.learn.c++. It is, however, instructive in not
depending blindly on optimizations in implementation and in what might
lead to such failures.


--
Martin Ambuhl mam...@earthlink.net

__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com


0 new messages