[Halld-offline] stl vector

David Lawrence davidl at jlab.org
Mon May 9 13:45:07 EDT 2011



Hi Paul et al.,

     I was a little hasty in my earlier comparison. It looks like the 
allocation of an STL vector can somehow take a lot longer than for an 
array. When I modified Paul's program to allocate memory only for the 
type of container being tested, I got a result much closer to what Paul 
had originally reported seeing, even when I turned optimization on:

No Optimization
--------------
1:11.11 STL
0:04.74 double array

-O
--------------
0:03.62 STL
0:01.20 double array

-O2
--------------
0:03.63 STL
0:01.21 double array


It's worth noting that when I copied the line allocating the STL vector 
into the TestArray() routine, it again erased the discrepancy. I suspect 
the reason is because STL vector elements are always initialized when 
the allocation is done. I'm not really sure what double() does, but it 
seems to take a lot of time. Allocating an array doesn't have that overhead.

The modified source is attached and the results of the session can, 
again, be found below.

Regards,
-David

wifi-80-86:STLTest>g++ stl-test.cc -o stl-test
wifi-80-86:STLTest>time ./stl-test stl
sumXsq = 2.69986e+17
68.825u 0.527s 1:11.11 97.5%    0+0k 0+0io 0pf+0w
wifi-80-86:STLTest>time ./stl-test array
sumXsq = 2.69986e+17
4.563u 0.039s 0:04.74 96.8%    0+0k 0+0io 0pf+0w

wifi-80-86:STLTest>g++ -O stl-test.cc -o stl-test
wifi-80-86:STLTest>time ./stl-test stl
sumXsq = 2.69986e+17
3.509u 0.028s 0:03.62 97.2%    0+0k 0+0io 0pf+0w
wifi-80-86:STLTest>time ./stl-test array
sumXsq = 2.69986e+17
1.168u 0.009s 0:01.20 96.6%    0+0k 0+0io 0pf+0w

wifi-80-86:STLTest>g++ -O2 stl-test.cc -o stl-test
wifi-80-86:STLTest>time ./stl-test stl
sumXsq = 2.69986e+17
3.512u 0.031s 0:03.63 97.5%    0+0k 0+0io 0pf+0w
wifi-80-86:STLTest>time ./stl-test array
sumXsq = 2.69986e+17
1.169u 0.011s 0:01.21 96.6%    0+0k 0+0io 0pf+0w



On 5/9/11 1:10 PM, Paul Eugenio wrote:
> Hi Dave,
>
> I am impressed by the compiler optimization.    After debugging, I usually use -O optimization, but I have to admit I did not expect near full recover.
>
> P.
>
>
> On May 9, 2011, at 12:21 PM, David Lawrence wrote:
>
>> Hi Paul,
>>
>>      I actually tried your code on my 2.33GHz Core 2 duo laptop running
>> OS X 10.5 and got a much larger discrepancy. However, when I turned on
>> optimization, the discrepancy disappeared. Have you tried this test with
>> optimization turned on?
>>
>>
>> No Optimization
>> --------------
>> 1:13.83 STL
>> 0:04.83 double array
>>
>> -O
>> --------------
>> 0:03.63 STL
>> 0:03.64 double array
>>
>> -O2
>> --------------
>> 0:03.68 STL
>> 0:03.64 double array
>>
>>
>>
>> Full transcript of session is below.
>>
>> Regards,
>> -Dave
>>
>> STL-vector
>> -------------------
>> wifi-80-86:STLTest>g++ stl-test.cc -o stl-test
>> wifi-80-86:STLTest>time ./stl-test
>> sumXsq = 2.69986e+17
>> 71.068u 0.584s 1:13.83 97.0%    0+0k 0+0io 0pf+0w
>> wifi-80-86:STLTest>g++ -O stl-test.cc -o stl-test
>> wifi-80-86:STLTest>time ./stl-test
>> sumXsq = 2.69986e+17
>> 3.498u 0.031s 0:03.63 96.9%    0+0k 0+0io 0pf+0w
>> wifi-80-86:STLTest>g++ -O2 stl-test.cc -o stl-test
>> wifi-80-86:STLTest>time ./stl-test
>> sumXsq = 2.69986e+17
>> 3.496u 0.033s 0:03.68 95.6%    0+0k 0+0io 0pf+0w
>>
>>
>> double with malloc
>> -----------------
>> wifi-80-86:STLTest>g++ stl-test.cc -o stl-test
>> wifi-80-86:STLTest>time ./stl-test
>> sumXsq = 0
>> 4.674u 0.036s 0:04.83 97.3%    0+0k 0+0io 0pf+0w
>> wifi-80-86:STLTest>g++ -O stl-test.cc -o stl-test
>> wifi-80-86:STLTest>time ./stl-test
>> sumXsq = 0
>> 3.498u 0.032s 0:03.64 96.7%    0+0k 0+0io 0pf+0w
>> wifi-80-86:STLTest>g++ -O2 stl-test.cc -o stl-test
>> wifi-80-86:STLTest>time ./stl-test
>> sumXsq = 0
>> 3.489u 0.027s 0:03.64 96.1%    0+0k 0+0io 0pf+0w
>>
>>
>> On 5/9/11 11:58 AM, Paul Eugenio wrote:
>>> g++     stl-test.cc   -o stl-test
>> _______________________________________________
>> Halld-offline mailing list
>> Halld-offline at jlab.org
>> https://mailman.jlab.org/mailman/listinfo/halld-offline
> --
> Prof. Paul Eugenio
> Florida State University
> Department of Physics
> Tallahassee, Florida,  USA 32306
>
> (850) 644-2585
> eugenio at fsu.edu
>
>
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: stl-test.cc
URL: <https://mailman.jlab.org/pipermail/halld-offline/attachments/20110509/d5f87d85/attachment.cc>


More information about the Halld-offline mailing list