
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday, May 25, 2011, Phil Bouchard wrote:
On 5/25/2011 1:39 PM, Frank Mori Hess wrote:
What version of boost are you referring to?
boost_1_46_1
make_shared used to be slow due to it doing a lot of unnecessary copying of the storage area for the pointee, but that should have been fixed probably a couple years back now. Copying a shared_ptr is fairly slow due to the atomic reference counting, but I would expect a compiler to be able to elide the copy of the make_shared return value.
That optimization doesn't exist and it's worse with the Intel Compiler:
Well, I was thinking of the case where you are initializing a newly declared shared_ptr as opposed to re-assigning the same shared_ptr over and over again. Running a trimmed down and tweaked version of your benchmark (attached) I get: $ g++ -O3 -Wall pb_benchmark.cpp -lrt fhess@tailpipe:~/test$ ./a.out new: shared_ptr: 17500558 ns make: shared_ptr: 12208956 ns Note, I moved the declaration of the shared_ptrs inside the loops. Also, your benchmark on my machine shows a strong dependence on the order the tests are run. The first run is slower, which is why the "new" result is before the "make" result above, to demonstrate the effect. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk3e5ewACgkQ5vihyNWuA4VYKgCgkXKZk+AqfXyzjQKmg4b65lbd mFsAoJGL5Leu1e45BaguXnk9O0zLllFe =XV7n -----END PGP SIGNATURE-----