From: Gustav Munkby Date: 2007-09-04T16:35:11+09:00 Subject: Re: [QUIZ] Twisting a Rope (#137) > CPU(user+sys,sec) mem(peak,MB) > ------------------- ------------ > build sort total build sort class > ----- ---- ----- ----- ---- ----- > 0.10 1.70 1.80 287 1327 String > 0.01 0.27 0.28 22 153 Porth::Rope > 0.02 0.83 0.85 22 34 Choudhury::Rope * > 0.02 0.06 0.08 22 29 Mahurin::StringRope + > 0.00 0.08 0.08 22 30 Mahurin::DenormalStringRope + > 0.02 0.14 0.16 22 29 Mahurin::MutableStringRope > 0.07 0.10 0.17 151 151 Munkby::ArrayRope > 0.02 0.73 0.75 22 655 Kalenkovich::Rope * Thanks for running the tests! I do think it is a shame, however, that the table does not include the notion of safety that I mentioned in my submission. If any of these classes should every go into a gem as ara mentioned, the user of that gem at least ought to be able to choose the safe version. Here is a very simple scenario where such a problem is introduced. One could probably do worse changes to the source strings, but this was the first example I came up with. ss = %w[test append] r1, r2 = ss.map {|x| Mahurin::StringRope.new(x) } r1 <<= r2 ss.first << "ing" r1.length # => 10 r1.to_s.length # => 13 I have only tested Mahurin::StringRope, but would like to know for which other classes I need to be extra careful when adding strings to the rope. I did find, however, that by removing my "safety dups", the combined running time (on my machine) is about the same for my solution as for Mahurin::StringRope. !g