in reply to Re: Re: Re: Re: Peeling the Peelings
in thread Peeling the Peelings

Somehow I introduced an error into the code. This is the code that produced the benckmark shown. The difference is the first condition on the while line. I'd did have to reformat the code when pasting to stop it wrapping as I edit my code using lines well over 100 chars. Quite how I managed to add the > 0 in there I can't explain. This does handle all cases. I'll update the original node to reflect the mistake.

sub buk2 { my( $s, $n ) = @_; my( $start, $stop ) = ( 0, length $s ); ($start,$stop) = ( 1 + index( $s, '(', $start ), rindex( $s, ')', $stop -1 ) ) while $n-- and index( $s, '(', $start +1 ) > 0; substr $s, $start, $stop - $start; }

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Peeling the Peelings
by bobn (Chaplain) on Jul 03, 2003 at 23:17 UTC
    And it looks like we have a new winner:
    Benchmark: timing 50000 iterations of Aristotle, Fatvamp, bobn, buk2.. +. Aristotle: 8 wallclock secs ( 9.22 usr + 0.00 sys = 9.22 CPU) @ 54 +22.99/s (n=50000) Fatvamp: 12 wallclock secs (12.30 usr + 0.00 sys = 12.30 CPU) @ 40 +65.04/s (n=50000) bobn: 8 wallclock secs ( 9.68 usr + 0.00 sys = 9.68 CPU) @ 51 +65.29/s (n=50000) buk2: 8 wallclock secs ( 8.42 usr + 0.00 sys = 8.42 CPU) @ 59 +38.24/s (n=50000) Benchmark: timing 50000 iterations of Aristotle, Fatvamp, bobn, buk2.. +. Aristotle: 11 wallclock secs ( 8.96 usr + 0.01 sys = 8.97 CPU) @ 55 +74.14/s (n=50000) Fatvamp: 17 wallclock secs (13.16 usr + 0.06 sys = 13.22 CPU) @ 37 +82.15/s (n=50000) bobn: 10 wallclock secs (10.29 usr + 0.01 sys = 10.30 CPU) @ 48 +54.37/s (n=50000) buk2: 8 wallclock secs ( 8.35 usr + 0.01 sys = 8.36 CPU) @ 59 +80.86/s (n=50000)
    Not sure why the variance, but in any case, you've edged out Aristotle.

    --Bob Niederman, http://bob-n.com