Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Update: Just before someone reads this, you might want to no that this does not answer the original question.

I've run the test, and got these results:

Benchmark: running Ordinary, Schwartzian for at least 2 CPU seconds... Ordinary: 2 wallclock secs ( 1.02 usr + 1.15 sys = 2.17 CPU) @ 55 +.30/s (n=120) Schwartzian: 2 wallclock secs ( 1.81 usr + 0.36 sys = 2.17 CPU) @ 8 +8.02/s (n=191)

So the Schwartzian transform is faster for me.

I have 170 files in the /bin directory.

Update:

I've moved the globbing out as merlyn has suggested.

I've also added a new sorting variant.

The code is:

#!perl use warnings; use strict; use Benchmark qw(timethese); our(@all, @sorted, @results); for my $dir ("/bin/", "/usr/bin/") { my $D; opendir $D, $dir; @all = readdir $D; closedir $D; chdir $dir; print "$dir contains ".@all." files\n"; sub sort_ord { @sorted = sort { -s $a <=> -s $b } @all; } sub sort_sch { @results = map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, -s $_], @all; } sub sort_new { my %h; @h{@all} = map {-s $_} @all; @results = sort { $h{$a}<=>$h{$b} } @all; } sub cmp_them { join("\n", @sorted) eq join("\n", @results) or die "bad sort"; } sort_ord; sort_sch; cmp_them; sort_new; cmp_them; timethese -5, { Ordinary => \&sort_ord, Schwartzian => \&sort_sch, Strange => \&sort_new, }; }

My results are:

/bin/ contains 172 files Benchmark: running Ordinary, Schwartzian, Strange for at least 5 CPU s +econds... Ordinary: 6 wallclock secs ( 2.18 usr + 3.08 sys = 5.26 CPU) @ 79 +.09/s (n=416) Schwartzian: 5 wallclock secs ( 4.69 usr + 0.58 sys = 5.27 CPU) @ 1 +34.72/s (n=710) Strange: 5 wallclock secs ( 4.60 usr + 0.64 sys = 5.24 CPU) @ 17 +8.44/s (n=935) /usr/bin/ contains 1397 files Benchmark: running Ordinary, Schwartzian, Strange for at least 5 CPU s +econds... Ordinary: 5 wallclock secs ( 1.91 usr + 3.15 sys = 5.06 CPU) @ 6 +.32/s (n=32) Schwartzian: 5 wallclock secs ( 4.73 usr + 0.52 sys = 5.25 CPU) @ 1 +2.95/s (n=68) Strange: 5 wallclock secs ( 4.67 usr + 0.55 sys = 5.22 CPU) @ 15 +.33/s (n=80)

I am surprised that Strange is a bit faster than Schwartzian, I thought it must be a little slower.

Btw, the two extra file in /bin are just . and .. that glob("/bin/*") do not return.


In reply to Re: Benchmark, -s versus schwartzian by ambrus
in thread Benchmark, -s versus schwartzian by Darby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (10)
    As of 2014-10-23 12:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (125 votes), past polls