in reply to Re: Re: noncase-sensitive sorting
in thread noncase-sensitive sorting

It shows that the simple sort is much faster than the Schwartzian sort, perhaps because of all the overheads the Schwartzian sort has.

Well, it shows that's the case with very little (and very simple) data. Instead of using little strings of a single character repeated up to ten times, try it with, say, 4k chunks of random character data. (I.e. use somthing like this to generate your @array:

foreach (0..1000) { my $string; $string .= ('a'..'z','A'..'Z')[rand 52] for 1 .. 4096; push @array, $string; }
With that change, I got these numbers:
Benchmark: timing 1000 iterations of Schwartzian, Simple... Schwartzian: 67 wallclock secs (66.85 usr + 0.04 sys = 66.89 CPU) @ 1 +4.95/s (n= 1000) Simple: 534 wallclock secs (533.43 usr + 0.06 sys = 533.49 CPU) @ + 1.87/s ( n=1000) Rate Simple Schwartzian Simple 1.87/s -- -87% Schwartzian 14.9/s 698% --
Does that show that the Scwartzian transform should definitely be used because it is 7 times as fast as without it? No. It shows, together with your results, that whether or not you choose to use an ST is (or should be) dependent both on the complexity of your sorting code and on the data you will be working with. It isn't black-or-white by any means.

It also shows that both lc and uc are O(N). Try the whole exercise again but sort by length and you'll probably find that there is no point to an ST at all. (Perl's length() is O(1).)

-sauoq
"My two cents aren't worth a dime.";