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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I just got the Perl CD Bookshelf version 4,and I am going through the exercises for the "learning Perl Objects, References, and Modules book. Chapter 7 ex 2 has you use Benchmark to compare the Schwartzian transformation versus a straight sort using -s. According to the answer, using the Schwartzian transformation should be faster, but I'm getting the opposite results. The Relevant code is:
use Benchmark qw(timethese); timethese( -2, { Ordinary => q{ my @results = sort { -s $a <=> -s $b } glob "/bin/*"; }, Schwartzian => q{ my @sorted = map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, -s $_], glob "/bin/*"; }, });
My results are:
Ordinary: 2 wallclock secs ( 0.61 usr + 1.64 sys = 2.25 CPU) @ 23 +7.78/s (n=535) Schwartzian: 2 wallclock secs ( 1.52 usr + 0.76 sys = 2.28 CPU) @ 2 +02.19/s (n=461)
If I do a 5000 iterations instead of 2 seconds, I get:
Benchmark: timing 5000 iterations of Ordinary, Schwartzian... Ordinary: 21 wallclock secs ( 6.46 usr + 14.78 sys = 21.24 CPU) @ 23 +5.40/s (n=5000) Schwartzian: 26 wallclock secs (17.15 usr + 8.45 sys = 25.60 CPU) @ 1 +95.31/s (n=5000)
The only reason I can think of is that I have a hyperthreading processor. Would that make the difference?
I'm running SuSE 9.1 with the perl version that came with it.
uname -a yields:
Linux dell 2.6.5-7.104-smp #1 SMP Wed Jul 28 16:42:13 UTC 2004 i686 i6 +86 i386 GNU/Linux
Perl -V yields:
Summary of my perl5 (revision 5.0 version 8 subversion 3) configuratio +n: Platform: osname=linux, osvers=2.6.4, archname=i586-linux-thread-multi uname='linux d209 2.6.4 #1 smp thu mar 11 17:56:49 utc 2004 i686 i +686 i386 gnulinux ' config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinp +erl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Dopti +mize=-O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -Wall -pipe' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemulti +plicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS +-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -Wal +l -pipe', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-stri +ct-aliasing' ccversion='', gccversion='3.3.3 (SuSE Linux)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +2 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', + lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags ='' libpth=/lib /usr/lib /usr/local/lib libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=, so=so, useshrplib=true, gnulibc_version='2.3.3' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynami +c -Wl,-rpath,/usr/lib/perl5/5.8.3/i586-linux-thread-multi/CORE' cccdlflags='-fPIC', lddlflags='-shared' Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL +_IMPLICIT_CONTEXT Built under linux Compiled at Apr 3 2004 00:52:08 @INC: /usr/lib/perl5/5.8.3/i586-linux-thread-multi /usr/lib/perl5/5.8.3 /usr/lib/perl5/site_perl/5.8.3/i586-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl
Thanks a lot.

In reply to Benchmark, -s versus schwartzian by Darby

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-12-08 01:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found