It Doesn't Matter

Image credit: http://img.wennermedia.com/920-width/rs-134918-buddy-holly.jpg

Bern -- 7th September 2018

Paul Johnson

@pjcjohnson


www.pjcj.net

Image credit: https://web.archive.org/web/20120724043245im_/http://yapceurope.lv/ye2011/img/rcc.jpg



In regione caecorum rex est luscus





Fast





Best





How?





How do I do X?





Use method A



But method B is faster





Let me benchmark!

Benchmark



              Rate   Method A  Method B
Method A  1298701/s        --      -24%
Method B  1703578/s       31%        --
    



So we should use method B?





Not so fast!



Is the benchmark correct?



1. Benchmarking is hard



2. Benchmarking is hard





Why do we use Perl?





Succint





Powerful





CPAN





Tools





Blazingly fast





Unicode





Blazingly fast

Trade runtime speed for development speed

Benchmark



              Rate   Method A  Method B
Method A  1298701/s        --      -24%
Method B  1703578/s       31%        --
    

This is not the bottleneck you are looking for



So we should use method B?

Rules of optimisation

Rules of optimisation



Michael A. Jackson

Rules of optimisation

Rule 1: Don't do it.

Michael A. Jackson

Rules of optimisation

Rule 1: Don't do it.
Rule 2 (for experts only): Don't do it yet.
Michael A. Jackson





Does it work?





Is it fast enough?





Are you sure?





Profile!





Fix your algorithm





Throw hardware





Cache something





Count the ops

How do I increment an array?


    

How do I increment an array?

map { $_ = $_ + 1 } @a
    

How do I increment an array?

map { $_ = $_ + 1 } @a
map { $_++ } @a
    

How do I increment an array?

map { $_ = $_ + 1 } @a
map { $_++ } @a
map $_++, @a
    

How do I increment an array?

map { $_ = $_ + 1 } @a
map { $_++ } @a
map $_++, @a
for (@a) { $_++ }
    

How do I increment an array?

map { $_ = $_ + 1 } @a
map { $_++ } @a
map $_++, @a
for (@a) { $_++ }
$_++ for @a
    

How do I increment an array?

map { $_ = $_ + 1 } @a
map { $_++ } @a
map $_++, @a
for (@a) { $_++ }
$_++ for @a
++$_ for @a
    





It Doesn't Matter!