It seems hard to answer in a completely generic fashion. If there's a
certain collection of vectors which you'd like to share structure, it
may be possible to put a number on the degree of sharing achieved by
examining the internals of those vectors. That wouldn't address the
issue of intermediate allocations internal to your algorithms, but
that might be fine.

As for a possible approach to the above, I've just added a function
called count-nodes to clojure.core.rrb-vector.debug (the JVM version
only) which counts all vector nodes used by a collection of vectors
(PV / gvec / RRB). An example from my REPL:

(let [vs (mapv (comp vec range) [2048 2048 2048])]
  [(apply dv/count-nodes (apply fv/catvec vs) vs)
   (apply dv/count-nodes (reduce into [] vs) vs)])
;= [203 396]

I might tweak the way it works a little (for example, it could take a
collection rather than varargs and count internal arrays rather than
nodes; the latter change could be beneficial, as tails are just arrays
without a node wrapper).

Hope this helps.

Cheers,
Michał


On 11 August 2014 14:56, Paul Butcher <p...@paulbutcher.com> wrote:
> Is there any way to benchmark the degree of structural sharing achieved by a
> Clojure algorithm? I'm evaluating two different implementations of an
> algorithm, one which uses zippers and one which uses rrb-vector. It would be
> great if there were some way to quantify the degree to which they both
> achieved (or didn't) structural sharing.
>
> --
> paul.butcher->msgCount++
>
> Silverstone, Brands Hatch, Donington Park...
> Who says I have a one track mind?
>
> http://www.paulbutcher.com/
> LinkedIn: http://www.linkedin.com/in/paulbutcher
> Skype: paulrabutcher
>
> Author of Seven Concurrency Models in Seven Weeks: When Threads Unravel
> http://pragprog.com/book/pb7con
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to