Boost logo

Boost Users :

Subject: Re: [Boost-users] Flyweight: wrapping shared_ptr
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2014-10-12 14:46:43


Akim Demaille <akim <at> lrde.epita.fr> writes:

>
> Hi Joaquín,
>
> The new bench is as follows:
>
> {
> size_t n = 10 * 1000;
> Exp exp = num(0);
> for (unsigned j = 1; j <= n; ++j)
> {
> Exp e = bin('*',
> bin('+', num(j), num(j)),
> bin('+', num(j), num(j)));
> Exp f = bin('/', e, e); // <======== a fancy "1"
> exp = bin('+', exp, f); // <======== so this is ++exp
> }
> assert(exp->eval() == n);
> }

I think you can make the test even more realistic: as it stands now,
the level of value redundancy is very low --for instance, each num
value is repeated only four times--, which is not the ideal setting
for Boost.Flyweight. If you change the creation of e to something like

        Exp e = bin('*',
                    bin('+', num(1+(j%m)), num(1+(j%m))),
                    bin('+', num(2+(j%m)), num(2+(j%m))));

for some constant m (in the range of 1000, for instance) then you
can modulate the level of redundancy (the lower m, the more duplicate
values): tuning m can tell you how Boost.Flyweight improves wrt the
shared_ptr case (which should not be affected by m at all). I bet
by having m sufficient low and n sufficiently high #7 can get to beat #1.
 
> which I ran on several implementations:
>
> [...]
>
> The results are:
>
> ./1 0,02s user 0,00s system 93% cpu 0,031 total
> ./7 0,06s user 0,00s system 97% cpu 0,070 total
> ./9 46,19s user 0,09s system 99% cpu 46,424 total
> ./10 171,29s user 9,71s system 99% cpu 3:01,09 total
> ./11 17,25s user 0,04s system 99% cpu 17,296 total
>

Well, seems like there's a clear winner here (ruling out #1, which
I understand from what you say it's not an acceptable alternative,
presumably because of memory limitations).

Joaquín M López Muñoz
Telefónica


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