[linux-audio-dev] soft synth as a plugin
Tim Goetze
tim at quitte.de
Fri Oct 18 18:48:01 UTC 2002
Stefan Nitschke wrote:
>>
>>erm, sorry, but why not use pointers?
>>
>
>Just out of couriosity i made a benchmark test between C and C++ with
>gcc3. I dont have a clue abour x86 assembler so i made a measurement.
>
>Here is the C code (not realy useful as real code would have a need for a
>struct and a pointer operation to call the filter() function) and the
>C++ code.
>Both "simulate" a low pass filter and are compiled with:
> gcc -O2 -march=pentium -o filter filter.xx
[...]
>C++ with member:
>real 0m11.847s
>user 0m11.850s
>sys 0m0.000s
>
>C++ with new() and pointer:
>real 0m12.337s
>user 0m12.330s
>sys 0m0.000s
>
>C:
>real 0m16.673s
>user 0m16.670s
>sys 0m0.000s
my interpretations:
c++ sans new() might be quicker because of better cache
locality (the class instance is just a local stack var,
while with new() it is somewhere on the heap in another
memory page).
i don't think reference and pointer access make the
difference, after all the internal representation should
be the same. granted, new() is a lot slower than a local
class on the stack but your code only allocates once.
have you checked whether the optimizer inlined the C
function call? it looks like it didn't.
tim
More information about the Linux-audio-dev
mailing list