-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Eric Niebler Sent: 06 July 2012 17:26 To: boost-users@lists.boost.org Subject: Re: [Boost-users] accumulators: not copying doubles into the acc set
Hello,
Having a list of doubles stored somewhere, is there a way not to copy
On 7/6/2012 8:32 AM, MM wrote: the
doubles into the accumulator set and just iterate somehow through the existing data in order to save memory.
Imagine I have a std::vector<double> with 10million entries.
Then pushing each double to the accumulator set object, then I'd imagine, at one point, the process would hold the 10 million doubles twice.
That's not true. Accumulators do not store the values they've seen. They only store enough intermediate information to calculate their result. For most accumulators, this is little to no information. Think of the count accumulator. It just increments an internal counter per value. Or sum. It just adds the value to a running sum and then discards the value. And the mean accumulator stores nothing at all. It just divides the result of the sum accumulator by the result of the count accumulator.
Right, it makes sense Now I tried to find 2 comparables ways of calculating the mean on a large number of doubles and time them http://codepad.org/12Uw654j Is this a fair comparison? 2. is twice as slow as 1. for the few runs I've done. It is understood the benefits from using acc set appear when calculating many moments that have common calculations, in a generic way, but I'd like to see the runtime cost of this feature MM