Boost logo

Boost Users :

From: Sohail Somani (s.somani_at_[hidden])
Date: 2006-10-24 20:37:06


> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Peng Yu
> Sent: Tuesday, October 24, 2006 5:33 PM
> Does it mean that code segment 1 is as fast as segment 2, but code
> segment 3 is the slowest?
>
> ///////1
> boost::shared_array a(new int[100]);
> for(int i = 0; i < 100; ++ i)
> a.get()[i] = i;
>
> ////////2
> boost::shared_array a(new int[100]);
> int a_ptr = a.get();
> for(int i = 0; i < 100; ++ i)
> a_ptr[i] = i;
>
> ////////3
> boost::shared_array a(new int[100]);
> for(int i = 0; i < 100; ++ i)
> a[i] = i;

All I can say is profile, profile, profile!

PS: Profile.
PPS: I'd guesstimate with a proper C++ compiler + optimizer, you
wouldn't notice much of a difference between 1 and 3.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net