Find the largest element



  • I just found a lovely gem of code while doing routine maintenance on a system.  The system pings a bunch of places for values, puts them all into an array, and then "sells" it's item to the place that returned the highest price.


    The code here gathers all the objects into an array and grabs the highest one. 

    I can't actually paste the code, but here's what he was doing:

     
    Grab Array

    Copy into new array

    Bubble sort the array!!!  Using his own bubble sort implementation!!

    something like $max = array[sizeof(array))] to get the last element.

    return $max

    Should I tell him that PHP has a built in function for finding the largest element of an array, or should I marvel at his own implementation of bubble sort?
     



  • @HockeyGod said:

    Should I tell him that PHP has a built in function for finding the largest element of an array, or should I marvel at his own implementation of bubble sort?

    I love this. Waste huge amounts of effort sorting values that will never be used...
     



  • heheh, the fact that he thought a sorting method will matter in the face of any I/O is WTF.  That's like spending 5 hours to find a short cut that saves you a .3 seconds on a 14 hour road trip.



  • @Vechni said:

    heheh, the fact that he thought a sorting method will matter in the face of any I/O is WTF.  That's like spending 5 hours to find a short cut that saves you a .3 seconds on a 14 hour road trip.

    Yikes! That's a pretty brazen repudiation of complexity. Write a PHP script to download 5000 web pages and then bubble sort them on  character length. Get back to us on which takes longer.
     



  • Wow...it's really that easy to find the largest element? I thought it involved particle accelerators and stuff. ;-)



  • @obediah said:

    @Vechni said:

    heheh, the fact that he thought a sorting method will matter in the face of any I/O is WTF.  That's like spending 5 hours to find a short cut that saves you a .3 seconds on a 14 hour road trip.

    Yikes! That's a pretty brazen repudiation of complexity. Write a PHP script to download 5000 web pages and then bubble sort them on  character length. Get back to us on which takes longer.
     

     

    So true. Ideas like "It doesn't matter that I'm using bubble sort because I'm doing I/O!" are why so much software falls over when it first encounters a strong breeze. 



  • No reason to sort at all.

    If all you want is the largest one, just set a variable to 0 and check each element.  If the element is greater then copy it's value into the variable and move on to the next one.  One quick pass through your list and you know the highest value.  No moving of elements, no copying of an entire array, no sorting of anything.  Just find the highest value.

    This is Occam's razor, find out what is the least you need to perform the job with the least amount of work.  Sorting may solve the problem but at a far greater cost no matter what sorting method you use. 



  • I should probably add that the recode simply checked to see if the value returned by the "ping" was higher and only stored 1 value - the highest... instead of storing all the other values that we'd just throw out anyway.



  • Would have been even funnier if he did selection sort in descending order.



  • Hmm, there's no need for an array, or sorting it.

     

    Just ping each site in turn, if the price is better than the last best price, remember this site..

     

    No arrays, no sorting.

     

     



  • And that's exactly how it was re-coded, Ancient_Hacker



  • The real WTF is that several people here feel the need to explain an algorithm that should be obvious. There goes our "elite" status...



  • I also thought it was funny to see all the people posting their super genius MAX_ELEMENT algorithms.

     

    Funny thing is, in Perl when I want to find the max element of an array I usually do this:


    my $max = shift sort @array;



    I save probably 15-20 seconds typing that than typing out the damn one pass.  I guess I could use map, but it would still be more typing.   Hmmm, if only Perl had foldr....



  • God damnit, we're supposed to be laughing at the idiots here.

     Now we have someone suggesting an O(n^2) algorithm doesn't matter in the face of I/O and a bunch of people who need to explain how to find the largest element in an array.

     Come on! Get your heads in the game!

     



  • @tster said:

    Funny thing is, in Perl when I want to find the max element of an array I usually do this:


    my $max = shift sort @array;



    I save probably 15-20 seconds typing that than typing out the damn one pass.  I guess I could use map, but it would still be more typing.   Hmmm, if only Perl had foldr....

    Thou shalt not reimplement the standard libraries. List::Util::max! It's been there for longer than I've been using perl.

    And besides, (a) that's not valid perl (you can't shift a list), (b) that's min, for pity's sake, and (c) you suck. Although at least the thread is getting back on track.

    Incidentally, foldl/foldr correspond roughly to List::Util::reduce



  • @HockeyGod said:

    something like $max = array[sizeof(array))] to get the last element.

    He, he, he, idiot! He's getting the last item of the array, instead of reversing the array and getting the first one.

    Why use a sledge hammer to drive in a nail, when you can use a bazooka with a bit more effort. DOH!

     -dZ.


  • @DZ-Jay said:

    @HockeyGod said:

    something like $max = array[sizeof(array))] to get the last element.

    He, he, he, idiot! He's getting the last item of the array, instead of reversing the array and getting the first one.

    Why use a sledge hammer to drive in a nail, when you can use a bazooka with a bit more effort. DOH!

     -dZ.</blockquote></p><p>Isn't he supposed to compare it to the largest value in the array to make sure he's got the right one?&nbsp;</p>


  • @Maciej said:

    @obediah said:

    @Vechni said:

    heheh, the fact that he thought a sorting method will matter in the face of any I/O is WTF.  That's like spending 5 hours to find a short cut that saves you a .3 seconds on a 14 hour road trip.

    Yikes! That's a pretty brazen repudiation of complexity. Write a PHP script to download 5000 web pages and then bubble sort them on  character length. Get back to us on which takes longer.
     

     

    So true. Ideas like "It doesn't matter that I'm using bubble sort because I'm doing I/O!" are why so much software falls over when it first encounters a strong breeze. 



    Why would you assume that someone wouldn't use bubblesort in any case after hearing that? In this case, bubblesort wouldn't matter, which is kind of why I stated that it wouldn't. Perhaps I stated that because it is true, and for him to spend all the time working on that indicates he doesn't understand how I/O and sorting, or comptuers in general work.

     
    Wouldn't software fallover from a strong breeze due to lack of education? Come back to us when you know how: processes are blocked, the relative time it takes for I/O vs. CPU cycles, how bubble sort is effective for values ranging near... I don't know, 1 million? as opposed to what you think, 5000... hint: it does not take a long time for the CPU reference an array, that referencing what is called a "pointer", not the entire element h0h0



     



  • @KattMan said:

    No reason to sort at all.

    If all you want is the largest one, just set a variable to 0 and check each element.  If the element is greater then copy it's value into the variable and move on to the next one.  One quick pass through your list and you know the highest value.  No moving of elements, no copying of an entire array, no sorting of anything.  Just find the highest value.

    This is Occam's razor, find out what is the least you need to perform the job with the least amount of work.  Sorting may solve the problem but at a far greater cost no matter what sorting method you use. 

     

    Why set it to 0 first? I can think of at least one instance where that would fail. Just use array[0] as the initial max.



  • Set it to 0 only because the problem domain allows that to be a valid starting point.

    We are looking for max price, it is safe to assume that this price will be positive.  I don't care if you have an array or are iterating through a data set or parsing a flat file.  In this case start at 0 and if the value currently read in is higher then save that instead and move on.

    If the problem domain was something other than price, and you know the input format (I'm assuming the arrays were because the guy didn't know what he was doing) then yes, use the first element. 

    I will agree though, the first element is valid in either case. The only issue is that you now make the first element a special case.  I could easily argue that you should not initialize it and leave it as null.  During checks if the saved value is null then replace it.  Of course now you are checking this through each pass.  That's why I initialize it first for the problem domain and treat every record, element, line the exact same; no special cases.



  • Never mind... everybody already pointed out the "don't start with 0" thing.



  • @Vechni said:

    @Maciej said:
    @obediah said:

    Yikes! That's a pretty brazen repudiation of complexity. Write a PHP script to download 5000 web pages and then bubble sort them on  character length. Get back to us on which takes longer.
     

     

    So true. Ideas like "It doesn't matter that I'm using bubble sort because I'm doing I/O!" are why so much software falls over when it first encounters a strong breeze. 



    Why would you assume that someone wouldn't use bubblesort in any case after hearing that? In this case, bubblesort wouldn't matter, which is kind of why I stated that it wouldn't. Perhaps I stated that because it is true, and for him to spend all the time working on that indicates he doesn't understand how I/O and sorting, or comptuers in general work.

     
    Wouldn't software fallover from a strong breeze due to lack of education? Come back to us when you know how: processes are blocked, the relative time it takes for I/O vs. CPU cycles, how bubble sort is effective for values ranging near... I don't know, 1 million? as opposed to what you think, 5000... hint: it does not take a long time for the CPU reference an array, that referencing what is called a "pointer", not the entire element h0h0

     

    Please try bubblesorting an array of 5000 elements before you start disparaging other people's understanding of the subject matter. 



  • @bobday said:

    God damnit, we're supposed to be laughing at the idiots here.

     Now
    we have someone suggesting an O(n^2) algorithm doesn't matter in the
    face of I/O and a bunch of people who need to explain how to find the
    largest element in an array. 

    Are you implying that if the sort algorithm had been O(log n) everything would have been ok?

    ;-)

     



  • @Maciej said:

    @Vechni said:
    @Maciej said:
    @obediah said:

    Yikes! That's a pretty brazen repudiation of complexity. Write a PHP script to download 5000 web pages and then bubble sort them on  character length. Get back to us on which takes longer.
     

     

    So true. Ideas like "It doesn't matter that I'm using bubble sort because I'm doing I/O!" are why so much software falls over when it first encounters a strong breeze. 



    Why would you assume that someone wouldn't use bubblesort in any case after hearing that? In this case, bubblesort wouldn't matter, which is kind of why I stated that it wouldn't. Perhaps I stated that because it is true, and for him to spend all the time working on that indicates he doesn't understand how I/O and sorting, or comptuers in general work.

     
    Wouldn't software fallover from a strong breeze due to lack of education? Come back to us when you know how: processes are blocked, the relative time it takes for I/O vs. CPU cycles, how bubble sort is effective for values ranging near... I don't know, 1 million? as opposed to what you think, 5000... hint: it does not take a long time for the CPU reference an array, that referencing what is called a "pointer", not the entire element h0h0

     

    Please try bubblesorting an array of 5000 elements before you start disparaging other people's understanding of the subject matter. 

     

     

    I don't know if I can, apparently I need to do this in "PHP script"

     

    ...or wait, If I write this in PHP, you are saying that it will suck and I will get the point?

     

    Maybe you should watch one of those applets on sorting applications where they show the bars sorting by length... or did you watch this video and think that sorting actually occurs that slow? Which is why you seem to think sorting 5000 elements is CPU intensive?



  • @DaveK said:

    @bobday said:

    God damnit, we're supposed to be laughing at the idiots here.

     Now
    we have someone suggesting an O(n^2) algorithm doesn't matter in the
    face of I/O and a bunch of people who need to explain how to find the
    largest element in an array. 

    Are you implying that if the sort algorithm had been O(log n) everything would have been ok?

    ;-)

     

    Considering that even the BEST sorting algorithms are O(n), things would be a lot more than ok.
     



  • @Random832 said:

    @DaveK said:
    @bobday said:

    God damnit, we're supposed to be laughing at the idiots here.

     Now
    we have someone suggesting an O(n^2) algorithm doesn't matter in the
    face of I/O and a bunch of people who need to explain how to find the
    largest element in an array. 

    Are you implying that if the sort algorithm had been O(log n) everything would have been ok?

    ;-)

     

    Considering that even the BEST sorting algorithms are O(n), things would be a lot more than ok.
     

    Wasn't the cap for sorting algorithms O(n log n)? In which case I wouldn't call it "ok" if all you need is a O(n) comparation algorithm ;)

    @Vechni said:

    Maybe you should watch one of those applets on sorting applications where they show the bars sorting by length

    You
    just give the perfect argument why you're utterly wrong. Please explain
    how these videos are supposed to show that there are valid uses for
    bubble sort.


     



  • @Vechni said:

    I don't know if I can, apparently I need to do this in "PHP script"

     

    ...or wait, If I write this in PHP, you are saying that it will suck and I will get the point?

     

    Well, strictly speaking, PHP is the language of the WTF, so that would be the most fair, but even in C, it won't take you more than 10,000-20,000 elements to get multi-second runtimes.



  • @PSWorx said:

    @Random832 said:
    @DaveK said:

    Are you implying that if the sort algorithm had been O(log n) everything would have been ok?

    Considering that even the BEST sorting algorithms are O(n), things would be a lot more than ok.

    Wasn't the cap for sorting algorithms O(n log n)? In which case I wouldn't call it "ok" if all you need is a O(n) comparation algorithm ;)

    Ω(n log n) is the lower bound for the problem of sorting against a total order, where the only operation you can use to inspect the values is the pairwise comparison operator. Faster sorts are possible using other methods. The lower bound for sorting overall is Ω(n), on the grounds that you cannot sort without looking at each element of the input data at least once.


  • @Random832 said:

    @DaveK said:
    @bobday said:

    God damnit, we're supposed to be laughing at the idiots here.

     Now
    we have someone suggesting an O(n^2) algorithm doesn't matter in the
    face of I/O and a bunch of people who need to explain how to find the
    largest element in an array. 

    Are you implying that if the sort algorithm had been O(log n) everything would have been ok?

    ;-)

     

    Considering that even the BEST sorting algorithms are O(n), things would be a lot more than ok.
     

    Well,
    that being so, it might have beneficial side-effects (such as
    converting all NP-problems into P, solving the halting problem, etc.
    etc.), but my point was that the best sorting algorithm for this
    application is in fact O(0).

     



  • There is a pretty big miscommunication here:

    If you are downloading 10k-20k pages, you will not notice the sorting time, which is why its run time to sort, compared to the I/O in this case of *several I/O reads per element*, is nothing.  What is really funny is that you seem to think "multi-second runetimes" is some kind of de facto no-no in anything computing: not everyone is a web dev who reads circle jerk articles.... I get dude, "don't use frames", "make sql optimzation", "css is cool".... thanks.

    Thanks for the lecture though, I take notes everytime you talk from now on actually, please, go on and continue to post such insights here... I just can't believe how much smarter you are than I am and how much you can teach me!



  • @KattMan said:

    No reason to sort at all.

    If all you
    want is the largest one, just set a variable to 0 and check each
    element.  If the element is greater then copy it's value into the
    variable and move on to the next one.  One quick pass through your
    list and you know the highest value.  No moving of elements, no
    copying of an entire array, no sorting of anything.  Just find the
    highest value.

    This is Occam's razor,

       No.  No, it isn't.

    [quote
    user="KattMan"] find out what is the least you need to perform the job
    with the least amount of work.  Sorting may solve the problem but
    at a far greater cost no matter what sorting method you use. 

    [/quote]

     
    Occam's razor is about minimising the number of entities in your
    ontological model of the universe.  It has nothing to say about
    how much work they do.  Occam's razor is about explanations, not techniques.  Design, not implementation.




  • @asuffield said:

    The lower bound for sorting overall is Ω(n), on the grounds that you cannot sort without looking at each element of the input data at least once.

     

    Actually, there's been a recent innovation in sort techniques, whereby you don't need to look at each element at least once, in fact, not even once.  See http://tinyurl.com/ydtop4 for more details, or see http://tinyurl.com/2gap2q for a full implementation in php.




  • @Vechni said:

    ...

    There's still absolutely no reason to go out of your way to use bubble sort in an industry situation. Any serious programming language will provide a sort() function, and failing to use that is gross incompetence.



  • @DaveK said:

    @KattMan said:

    This is Occam's razor,

       No.  No, it isn't.

    [quote
    user="KattMan"] find out what is the least you need to perform the job
    with the least amount of work.  Sorting may solve the problem but
    at a far greater cost no matter what sorting method you use. 

     
    Occam's razor is about minimising the number of entities in your
    ontological model of the universe.  It has nothing to say about
    how much work they do.  Occam's razor is about explanations, not techniques.  Design, not implementation.


    [/quote]

    Then you missed it   I stated, "find out what is the least you need to perform the job with the least amount of work"  This is design, this is explanation.  After you find out, you then implement.  You start with all these different ways of doing it and you find the one that needs the least moving parts.  I said nothing about how to implement that afterwards.  This is an example of applying Occam's Razor to the problem, which the programmer did not do.  I went from the given large array to using just a single value to save the max.  How you implement that is up to you.



  • @DaveK said:

    Occam's razor is about minimising the number of entities in your ontological model of the universe.  It has nothing to say about how much work they do.  Occam's razor is about explanations, not techniques.  Design, not implementation.


    Implementation === design, right down to the naming of your variables.

    @Vechni said:
    If you are downloading 10k-20k pages, you will not notice the sorting time, which is why its run time to sort, compared to the I/O in this case of several I/O reads per element, is nothing.  What is really funny is that you seem to think "multi-second runetimes" is some kind of de facto no-no in anything computing: not everyone is a web dev who reads circle jerk articles.... I get dude, "don't use frames", "make sql optimzation", "css is cool".... thanks.


    Can't say for certain without testing, but bubble sort on 5000 elements seems to be on the same grounds as the usual bottleneck of parsing the code and serving the page. But one must agree that removing those IOs per element makes the sort the bottleneck, keeping it slower than most PHP pages despite the grand optimization of removing the IOs.

    @Vechni said:
    Maybe you should watch one of those applets on sorting applications where they show the bars sorting by length... or did you watch this video and think that sorting actually occurs that slow? Which is why you seem to think sorting 5000 elements is CPU intensive?


    There's that other site the URL of which I don't have anymore which lists most sorting algorithms in the same or similar tiny Java applets including source code but which Java applets run way way way faster than on the page you linked (don't know why -- I don't blame you) and Bubble sort still was in the Visibly Real Fucking Slow department while Quicksort was like Flop Flop done.

    Q: I need to sort, what algo--
    A: Quicksort.

    @Vechni said:
    Thanks for the lecture though, I take notes everytime you talk from now on actually, please, go on and continue to post such insights here... I just can't believe how much smarter you are than I am and how much you can teach me!


    omg you take notes too?



  • @Vechni said:

    not everyone is a web dev who reads circle jerk articles.... I get dude, "don't use frames", "make sql optimzation", "css is cool".... thanks.

     

    Hey guy, if you think that using a pre-packaged function over re-writing the canonical example of "bad algorithm" is "circle jerking", then knock yourself out, and use random-reorder sort for all I care. I'll be writing readable, scalable code that doesn't waste my time or the computer's on solved problems like sorting.
     



  • @dhromed said:

    @DaveK said:
    Occam's razor is about minimising the number of entities in your ontological model of the universe.  It has nothing to say about how much work they do.  Occam's razor is about explanations, not techniques.  Design, not implementation.


    Implementation === design, right down to the naming of your variables.

    That's just plain wrong. A design is definitely something completely different then a implementation.  How on earth could you implement a design, if by your logic the design is the implementation.
    Not to mention that the same design could be implemented in many different languages, resulting in slightly different implementations.

    Normally you make reasonable arguments, but this is just bs.




  • the problem with saying that the IO of the pings will take longer than the bubblesort is that pinging is O(n).  the pinging will be faster than even the fastest possible sort given enough elements.



  • @stratos said:

    @dhromed said:
    Implementation === design, right down to the naming of your variables.


    That's just plain wrong. A design is definitely something completely different then a implementation.  How on earth could you implement a design, if by your logic the design is the implementation.


    The implementation [in a language] is a form of design that comes after the technical design.

    For example,

    The functional spec says: have alternatingly coloured rows.
    The technical design says: in the writer loop, determine whether the iteration's number is even or odd and then fork something.

    Possible implementation designs in my pet language, JS:

    i % 2 == 0 //even

    (i & 1) == 0 // even!

    These are both implementations of the functional spec. Just with different code designs.

    Design is nothing more than the decision making process. If I name my variable A or B -- that's design (really bad design because damn who names their vars A and B?). To decide means to design.

    I also designed my post by removing a big ball of text that did the same as the example. How's that for refactoring!

    Normally you make reasonable arguments


    and thx.



  • @tster said:

    the problem with saying that the IO of the pings will take longer than the bubblesort is that pinging is O(n).  the pinging will be faster than even the fastest possible sort given enough elements.

    Pinging www.worsethanfailure.com from my machine takes 112ms right now. Pings within my country do about a dozen ms. That's a reasonable amount of run time. Would a single bubble sort of 5000 elements be in the same ballpark as 5000 of such pings?



  • so the question becomes what do you define as "a bunch of places".   If this number is less than 1000 then it doesn't matter.  This assumes you are pinging computers on your local network.  If you are pinging someone on the internet that becomes more like 2500-3000.  BTW, the perl built in sort will be meaningless compared to the pings for a long time (maybe 20-30 million... I didn't run the benchmark)

     

    Benchmark:

    Linux 2.66 GhZ intel
    Large Enterprise network after hours (therefor not saturated)


    Code follows: 

    use Net::Ping;

     $p = Net::Ping->new("tcp", 2);
        # Try connecting to the www port instead of the echo port
        $p->{port_num} = getservbyname("http", "tcp");

    my @array = ();
    my $start = time;
    my $num = 0;
    my $num_fail = 0;
    foreach (1..shift)
    {
        $num++;
        $num_fail++ unless($p->ping("www.microsoft.com"));
        push @array, rand(100000);
    }
    my $end = time;

    print "$num_fail ping failures...\n";

    print "pings:     " . ($end - $start) . "\n";

    my @array2 = @array;

    print "about to sort an array of size " . scalar @array; print "\n\n";

    $start = time;
    bubblesort(\@array);
    $end = time;

    print "bubblesort: " . ($end - $start) . "\n";

    $start = time;
    @array2 = sort @array2;
    $end = time;

    print "perl sort:  " . ($end - $start) . "\n";



    sub bubblesort {
        my ( $array ) = @_;

        use integer;        # More speed.

        my $lastj   = $#$array or return;
        my $firstj  = 1;

        my ( $i, $j, $keepj, $big );

        return if $firstj > $lastj;     # 0 or 1 element array is sorted.

        while ( $firstj ) {
            # Run from
            # ( $firstj - 1, $firstj ) .. ( $lastj - 1 , $lastj ),
            # swapping when out of order.
            for ( $j = $firstj, $i = $j - 1,
                  $keepj = $lastj, $firstj = 0;
              $j <= $keepj;
              $i = $j++ ) {
            next unless $array->[ $i ] gt $array->[ $j ];

            # Remember where we started if this is the first swap
            # (but do not try to compare with the predecessor of 0)
            $firstj = $firstj || $i || $j;

            # Something to swap, try for a run of swaps.
            # Remove the element that must swap up.
            $big = splice @$array, $i, 1;

            # Use $j < $keepj instead of $j <= $keepj
            # because the array is one shorter right now.
            # We already tested the $j entry that has been
            # shifted to $j-1.
            ++$j while $j < $keepj && $array->[ $j ] lt $big;

            # Put back the removed element in its new place.
            splice @$array, $j, 0, $big;

            # fix $j for the splice, and revalidate $i.
            $i = $j++;
            $lastj = $i;
            }
        }
    }




  • @dhromed said:

    @tster said:

    the problem with saying that the IO of the pings will take longer than the bubblesort is that pinging is O(n).  the pinging will be faster than even the fastest possible sort given enough elements.

    Pinging www.worsethanfailure.com from my machine takes 112ms right now. Pings within my country do about a dozen ms. That's a reasonable amount of run time. Would a single bubble sort of 5000 elements be in the same ballpark as 5000 of such pings?

    pinging server on my network

    boonet@l82ab016:/emc/boonet/Repository/symapi/perlexec$ perl sort.pl 2000
    pings:     1
    about to sort an array of size 2000
    bubblesort: 2
    perl sort:  0
    boonet@l82ab016:/emc/boonet/Repository/symapi/perlexec$ perl sort.pl 5000
    pings:     3
    about to sort an array of size 5000
    bubblesort: 19
    perl sort:  0

     

    pinging google.com

    boonet@l82ab016:/emc/boonet/Repository/symapi/perlexec$ perl sort.pl 10000 ping failures...
    pings:     4
    about to sort an array of size 1000
    bubblesort: 1
    perl sort:  0
    boonet@l82ab016:/emc/boonet/Repository/symapi/perlexec$ perl sort.pl 2000
    0 ping failures...
    pings:     7
    about to sort an array of size 2000
    bubblesort: 2
    perl sort:  0
    boonet@l82ab016:/emc/boonet/Repository/symapi/perlexec$ perl sort.pl 3000
    0 ping failures...
    pings:     10
    about to sort an array of size 3000
    bubblesort: 5
    perl sort:  0
    boonet@l82ab016:/emc/boonet/Repository/symapi/perlexec$ perl sort.pl 5000
    0 ping failures...
    pings:     19
    about to sort an array of size 5000
    bubblesort: 18
    perl sort:  0

     



  • @tster said:

    BTW, the perl built in sort will be meaningless compared to the pings for a long time (maybe 20-30 million... I didn't run the benchmark)

    Comparing a bubble sort written in perl to perl's builtin sort function is somewhat unfair, since the sort builtin is implemented in C, and gcc is a much better compiler than perl 5.



  • It's a valid comparison because I was doing this in response to a post questioning the use of a bubble sort implemented in Perl to the Perl built in sort.  Also, while the same algorithm will certainly run faster in C than in Perl, the asymptotic complexity will be the same, so the results will be the same just with different numbers.


Log in to reply