kokolo said:
I tried referencing like this:
........
my $l_ref=\@smaller_numbers;
my $r_ref=\@larger_numbers;
if ($#smaller_numbers > 0){@smaller_numbers = &qs(@$l_ref)}
if ($#larger_numbers > 0) {@larger_numbers = &qs(@$r_ref)}
This doesn't do anything at all. You are still doing just as much
allocating and copying and passing as you were before.
Well, there was nothing wrong with it per se, but it doesn't accomplish
anything. You would need to change the qs to take a reference, rather than
an array, and then pass the reference ($l_ref, not @$l_ref) into the sub
call. But that would only solve one quarter of the problem. You would
still be allocating @smaller_numbers and @larger_numbers and copying
everything into them. And you would still be taking the results of the
recursive call and copying them back into a big array to be returned, and
then copying it again in the return itself.
That said, your program does seem to be N**2, rather than NlogN, and I see
no reason that it should be. Even with all the badness built in, it should
still be NlogN, or maybe N(logN)**2, not N**2. I don't quite get it.
I wonder how good QuickSort can be in Perl so it will show me how bad or
good my algorithm is.
It can be at least 100 times faster. ("use sort '_quicksort';" give me
a built in sort that takes <1 second to sort 305780 numbers, versus 140
seconds for your sort). OK, so that may not qualify as being "in Perl",
because I'm sure much of it in C, but is available from Perl and still
uses the Perl variable access methods and such.
Xho