in reply to Re: Rere: pluralization
in thread pluralization
well, the abs() call is only there for the case of -1 -- you can take it out to compare against your case, or put some other check in to your case such that -1 == $count behaves the same as 1 == $count. otherwise you're comparing apples & oranges.
also, my snippet used two interpolations where yours reduced it to one ($noun versus the constant iteration) which doesn't make a huge difference, but again, them citrus fruits... time for me to run home. if you haven't rebenched, I'll set one up that's as parallel as possible except for x vs. ?:
ps: I don't know how the x operator is implemented, which is why i said "theoretically" faster -- as far as i can tell, there is no need for it to include a branch.
UP-dilly-DATE : OK, i didn't do it last night, but I did it. I made this small change:
sub sub1() { for my $count (0..2) { my $declension = 's' x ($count != 1); my $result = sprintf "$count iteration$declension so far...\n" +; } }
and got ... actually, quite similar results:
timethis 2000000: 52 wallclock secs (26.95 usr + 0.39 sys = 27.34 CPU +) @ 73152.89/s (n=2000000) timethis 2000000: 38 wallclock secs (25.47 usr + 0.34 sys = 25.81 CPU +) @ 77489.35/s (n=2000000)
Which is interesting, to me.
|
|---|