Boost logo

Boost :

From: Rene Rivera (grafik.list_at_[hidden])
Date: 2005-04-14 15:13:55


Rene Rivera wrote:
> Rene Rivera wrote:
>
>> I running the timing tests again, with some changes to see if I can
>> get more representative numbers. But attached is the end result.
>
>
> With a changed test that exercises all three functions, here's the
> timing results:
>
> sp_counted_base_w32.hpp...
> debug: 15.673 - release: 7.151
>
> sp_counted_base_cw_x86.hpp...
> debug: 15.943 - release: 6.499
>
> sp_counted_base_nt.hpp...
> debug: 15.933 - release: 6.499
>
> So the the hand assembly is as fast as the non-threading version. But is
> both slower and faster than the Interlocked* version. What gives? Is
> there a better smart_ptr timing test out there? I'm including the one I
> used.

Darn... attached the wrong file :-( Here's the one that really works..

-- 
-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. - http://redshift-software.com
-- rrivera/acm.org - grafik/redshift-software.com
-- 102708583/icq - grafikrobot/aim - Grafik/jabber.org

#include <boost/config.hpp>

#if defined(BOOST_MSVC)
#pragma warning(disable: 4786) // identifier truncated in debug info
#pragma warning(disable: 4710) // function not inlined
#pragma warning(disable: 4711) // function selected for automatic inline expansion
#pragma warning(disable: 4514) // unreferenced inline removed
#endif

//
// shared_ptr_timing_test.cpp - use to evaluate the impact of thread safety
//
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <iostream>
#include <vector>
#include <ctime>

int const n = 4 * 1024 * 1024;
int const r = 4;

int main()
{
    using namespace std;

    std::vector< boost::shared_ptr<int> > v(n);
    std::vector< boost::weak_ptr<int> > w(n);
    std::vector< boost::shared_ptr<int> > x(n);
    boost::shared_ptr<int> pi(new int);

    clock_t t = clock();
    {
        for (int i = 0; i < r; ++i)
        {
            v.assign(n,pi);
            w.assign(v.begin(),v.end());
            for (int j = 0; j < n; ++j) { x[j] = w[j].lock(); }
            v.assign(n,boost::shared_ptr<int>());
            w.assign(n,boost::weak_ptr<int>());
            x.assign(n,boost::shared_ptr<int>());
        }
    }
    t = clock() - t;

    std::cout << static_cast<double>(t) / CLOCKS_PER_SEC << '\n';

    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk