Bench Marking Perl
Bench Marking Perl
brian d foy Stonehenge Consulting Ser vices March 14, 2006 Chicago UniForum
Single Points
Multiple Points
Nobody is ferpect
Its only relative It has to be the same answer next time If something changes, the reference is meaningless
Computer Benchmarks
Standard Performance Evaluation Corporation (SPEC) CPU (2000, 95, 92) Graphics Web ser vers
http:/ /www.spec.org/
Language Shootout
Benchmarking programming languages?
How can we benchmark a programming language? We can't - we benchmark programming language implementations. How can we benchmark language implementations? We can't - we measure particular programs. http:/ /shootout.alioth.debian.org/
Performance
A major factor in determining the overall productivity of a system, performance is primarily tied to availability, throughput and response time.
http:/ /www.comptia.org/sections/ssg/glossary.aspx
Performance (2)
A performance comprises an event in which generally one group of people behave in a particular way for another group of people
http:/ /en.wikipedia.org/wiki/Performance
Performance (3)
Your investment's activity over time. Past performance does not guarantee future results.
My accountant
Availability Disk Use Concurrent Users CPU Time Completion Time Memory Use Uptime Bandwidth Use Net work Lag Responsiveness Binary Size
Programmer Time
TIMTOWTMI
Memory Use
use Devel::Size qw(size total_size); my $size = size("A string"); my @foo = (1, 2, 3, 4, 5); my $other_size = size(\@foo); my $foo = { a => [1, 2, 3], b => {a => [1, 3, 4]} }; my $total_size = total_size($foo);
Need PERL_DEBUG_MSTATS
...and it sux...
Sux : Sucks :: Kwalitee : Quality
Common misuse
use Benchmark 'cmpthese'; my @long = ('a' .. 'z', ''); my $iter = shift || -1; cmpthese( $iter,{ long_block_ne long_block_len long_bare_ne long_bare_len } );
http:/ /www.perlmonks.org/index.pl?node_id=536503
This is perl, v5.8.4 built for darwin-2level Summary of my perl5 (revision 5 version 8 subversion 4) configuration: Platform: osname=darwin, osvers=7.3.1, archname=darwin-2level uname='darwin albook.local 7.3.1 darwin kernel version 7.3.1: mon mar 22 21:48:41 pst 2004; root:xnuxnu-517.4.12.obj~2release_ppc power macintosh powerpc ' config_args='' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-pipe -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strictaliasing', optimize='-Os', cppflags='-no-cpp-precomp -pipe -fno-common -DPERL_DARWIN -no-cpp-precomp -fnostrict-aliasing' ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1640)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='' libpth=/usr/lib libs=-ldbm -ldl -lm -lc perllibs=-ldl -lm -lc libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup'
Do something useful
use Benchmark 'cmpthese'; our @long = ('a' .. 'z', ''); my $iter = shift || -1; cmpthese( $iter,{ long_block_ne long_block_len long_bare_ne long_bare_len } );
= = = =
= = = =
Theory of Measurement
Obser vation changes the universe Nothing is objective Tools have inherent uncertainities
Precision is repeatability
precision != accuracy
Benchmark.pms benchmark
Uses a null loop as a control sub { } Its just a timer Subtracts the null loop time Introduces an error of about 7%
http:/ /ppt.perl.org/
$ perl -MO=Concise -e 'grep { lc } @array' a 1 2 7 6 3 9 8 5 4 <@> leave[1 ref] vKP/REFC ->(end) <0> enter ->2 <;> nextstate(main 2 -e:1) v ->3 <|> grepwhile(other->8)[t4] vK/1 ->a <@> grepstart K*/2 ->7 <0> pushmark s ->4 <1> null lK/1 ->4 <1> null sK/1 ->7 <@> scope sK ->7 <0> ex-nextstate v ->8 <1> lc[t2] sK/1 -><1> ex-rv2sv sK/1 ->9 <$> gvsv(*_) s ->9 <1> rv2av[t3] lKM/1 ->6 <$> gv(*array) s ->5
$ perl -MO=Concise -e '() = grep { lc } @array' d 1 2 c 3 8 7 4 a 9 6 5 b <@> leave[1 ref] vKP/REFC ->(end) <0> enter ->2 <;> nextstate(main 2 -e:1) v ->3 <2> aassign[t5] vKS/COMMON ->d <1> ex-list lK ->b <0> pushmark s ->4 <|> grepwhile(other->9)[t4] lK/1 ->b <@> grepstart lK*/2 ->8 <0> pushmark s ->5 <1> null lK/1 ->5 <1> null sK/1 ->8 <@> scope sK ->8 <0> ex-nextstate v ->9 <1> lc[t2] sK/1 -><1> ex-rv2sv sK/1 ->a <$> gvsv(*_) s ->a <1> rv2av[t3] lKM/1 ->7 <$> gv(*array) s ->6 <1> ex-list lK ->c <0> pushmark s ->c <0> stub lPRM* ->-
$ perl -MO=Concise -e 'my @selected = grep { lc } @array' e 1 2 d 3 8 7 4 a 9 6 5 b c <@> leave[1 ref] vKP/REFC ->(end) <0> enter ->2 <;> nextstate(main 2 -e:1) v ->3 <2> aassign[t6] vKS ->e <1> ex-list lK ->b <0> pushmark s ->4 <|> grepwhile(other->9)[t5] lK/1 ->b <@> grepstart lK*/2 ->8 <0> pushmark s ->5 <1> null lK/1 ->5 <1> null sK/1 ->8 <@> scope sK ->8 <0> ex-nextstate v ->9 <1> lc[t3] sK/1 -><1> ex-rv2sv sK/1 ->a <$> gvsv(*_) s ->a <1> rv2av[t4] lKM/1 ->7 <$> gv(*array) s ->6 <1> ex-list lK ->d <0> pushmark s ->c <0> padav[@selected:2,3] lRM*/LVINTRO ->d
Tony Hoare
What do I benchmark?
Summary
Decide what is important to you Realize you have bias Report the situation Dont turn off your brain Make predictions that you can verify
Further Reading
Benchmarking, The Perl Journal #11, http:/ /www.pair.com/~comdog/Articles/benchmark.1_4.txt Wasting Time Thinking About Wasted Time, http:/ /www.perlmonks.org/?node_id=393128 Proling in Perl, http:/ /www.ddj.com/documents/s=1498/ddj0104pl/