SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
Benchmarking, Statistics &
PHPBench
A framework for creating glorious benchmarks
by Daniel Leech
@dantleech @phpbench
About Me
● Daniel Leech
● PHP Developer
– Symfony CMF and associated projects
● PHPCR-ODM, Jackalope, PHPCR
– Sulu CMF
– PHPBench
● Cycle tourer
What is Benchmarking?
SCPT
● Testing: Running an operation and obtaining a
result.
● Performance: We are concerned about the
performance of the subject.
● Comparative: Ultimately, we are always concerned
about the performance of one thing as compared to
another thing.
● Standardized: The tests should be standardized so
that they can be applied meaningfully to all subjects.
Differences to Profiling
Benchmarking Profiling
Measures External wall time Internal call times
Observer effect? Minimal Major
Scope (typical) Scenario Request
Applies to (typical) Libraries Applications
Benchmarking Script
<?php
$a = array();
$start = microtime( true );
for ($i = 0; $i < 10000; ++$i) {
isset($a['key']);
}
$total_time = microtime( true ) - $start;
echo "Total time: ", number_format($total_time, 6), PHP_EOL;
$start = microtime( true );
for ($i = 0; $i < 10000; ++$i) {
in_array('key', $a);
}
$total_time = microtime( true ) - $start;
echo "Total time: ", number_format($total_time, 6), PHP_EOL;
http://stackoverflow.com/questions/13483219/what-is-faster-in-array-or-isset
found in the wild
Issues
● Boilerplate code.
● Relies on single samples.
● Results are not persisted.
● Not scalable.
Benchmarking Framework Should
● Execute code units.
● Perform tests multiple times to verify results.
● Provide visual feedback.
● Perform statistical analysis.
● Be able to serialize and store results.
Concepts
Revolutions
Number of times we consecutively execute our
benchmark subject.
<?php
$revolutions = 10000;
for ($i =0; $i < $revolutions; $i++) {
// do something
}
Iterations
Each iteration records the time taken to execute
the revolutions.
<?php
$iterations = 100;
$revolutions = 10000;
$results = [];
for ($iteration = 0; $iteration < $iterations; $iteration++) {
$startTime = microtime(true);
for ($rev = 0; $rev < $revolultions; $rev++) {
// do something
}
$time = microtime(true) - $startTime;
$times[] = $time;
}
illustrative example
Subjects
The actual code we are benchmarking.
Subjects could be:
– PHP internal functions.
– User functions (think unit tests).
– User services (think functional tests).
– External services.
– Anything you can wrap in a function.
Subjects
<?php
isset($a['b']);
<?php
$pdoConnection->query(“SELECT * FROM foo”);
<?php
$container->get('some.service');
<?php
$guzzle->get('https://github.com/phpbench/phpbench');
Algorithms
External services
User libraries
HTTP
Benchmarking with PHPBench
PHPBench is a command line based
benchmarking tool similar to PHPUniut.
$ phpbench
phpbench version 0.10.0-dev
Usage:
command [options] [arguments]
...
Available commands:
help Displays help for a command
list Lists commands
report Generate a report from an XML file
run Run benchmarks
Benchmark Class
● Class name suffixed
with “Bench”.
● Subject prefixed with
“bench”.
● Does not know about
PHPBench.
<?php
class HashBench
{
public function benchHash()
{
md5('hello world');
}
}
HashBench.php
actual working example!
Benchmark Class
● Annotations
determine how the
subject is executed.
● Class and/or method
level.
● Aware of class
inheritance.
<?php
class HashBench
{
/**
* @Revs(10000)
* @Iterations(100)
*/
public function benchHash()
{
md5('hello world');
}
}
HashBench.php
Running Benchmarks
$ phpbench run HashBench.php
PhpBench 0.9.0-dev. Running benchmarks.
HashBench
benchHash I9 P0 μ/r: 1.716μs μSD/r 0.099μs μRSD/r: 5.77%
1 subjects, 10 iterations, 0 revs, 0 rejects
(min mean max) = 1.567 1.716 1.887 (μs)
⅀T: 17.160μs μSD/r 0.099μs μRSD/r: 5.772%
I: Iteration #
P: Parameter set #
/r: Times are divided by
number of revolutions.
μ: Mean (average).
μs: Microseconds.
⅀T: Total time.
SD: Standard deviation.
RSD: Relative standard
deviation.
Running Benchmarks
$ phpbench run HashBench.php
PhpBench 0.9.0-dev. Running benchmarks.
HashBench
benchHash I9 P0 μ/r: 1.716μs μSD/r 0.099μs μRSD/r: 5.77%
1 subjects, 10 iterations, 0 revs, 0 rejects
(min mean max) = 1.567 1.716 1.887 (μs)
⅀T: 17.160μs μSD/r 0.099μs μRSD/r: 5.772%
● Progress loggers provide realtime feedback.
● Specified with --progress
● Reports can also be generated.
Stability and Accuracy
Revolutions
<?php
$revolutions = 10000;
$start = microtime(true);
for ($i =0; $i < $revolutions; $i++) {
md5('hello world');
}
$elapsed = microtime(true) - $start;
How do revolutions affect time?
Revolutions
<?php
$time = $iterationTime / $revolutions;
Reported time is total time divided by number of revolutions.
Answers the question:
What is the average execution time of the method?
Revolutions Time (µs/r)
1 10 100%
2 6 60%
4 3.75 37.5%
8 2.625 26.2%
16 2.188 21.8%
32 1.969 19.6%
64 1.75 17.5%
10,000 1.72 17.2%
Micro Revolutionary Effect
● Includes microtime
and loop calls.
● Begins to stabilise at
~32 revolutions.
● Regression to ~17%
of first value.
Micro (microseconds) benchmarks are heavily affected by
the number of revolutions.
Revolutions Time (ms/r)
1 512 100%
2 407 79%
4 381 74%
8 375 73%
16 408 79%
32 369 72%
64 367 71%
Macro Revolutionary Effect
● Warmup factor
(autoload cache, etc)
● Earlier stabilisation.
● Regression to 71% of
first value.
Macro (milliseconds, seconds) benchmarks less affected.
Iterations
<?php
class HashBench
{
/**
* @Revs(10000)
* @Iterations(100)
*/
public function benchHash()
{
md5('hello world');
}
}
● Each iteration
provides a time
measurement.
● Iterations produce a
range of different time
measurements.
Iterations
Iteration μ Time (μs)
1 2.766
2 2.773
3 2.737
4 2.782
5 2.776
6 2.716
7 2.729
.. ..
Histogram
Normal Distribution
● Applies to any set of
random variables with
an Expected Value.
● Benchmark times
should be normally
distributed.
● Peak is the most
probable time.
Outliers!
The Mean and the Mode
Mean: Average value of the set:
Mode: Most common value in the set...
Determining the mode
https://en.wikipedia.org/wiki/Kernel_density_estimate
kernel density estimatehistogram
Measuring Stability
Standard Deviation (SD)
● Unit represented as “sigma” σ
● Almost the average distance between values
in the set.
● An SD of zero indicates that all the values are
identical.
● Relative standard deviation (RSD) is the SD
divided by the mean. It is a percentage.
● RSD provides a comparable number.
Standard Deviation
|
RSD = 3%
MEAN = 2.078
MIN = 2.5
MAX = 3.2
Standard Deviation
RSD = 30%
MEAN = 3.440
MIN = 2
MAX = 6
Standard Deviation
RSD = 11%
MEAN = 2.793
MIN = 2.5
MAX = 4.5
Improving Stability
Shutdown Unecessary Stuff
● No music processes.
● No video processes.
● No Grand Theft Aauto.
Retry Threshold
Keep running the iteration set until all times fall
into a given margin of error (MOE).
● Feature of PHPBench
● Retries iterations when they fall outside of the
MOE.
phpbench run examples/HashBench.php --retry-threshold=2
RSD: 5.7%
16% retry threshold
RSD: 1.9%
4% retry threshold
RSD: < 1%
2% retry threshold
Take Away
● Use a large number of revolutions for micro
benchmarks (at least 1000).
● For best results use a large number of
Iterations (100-500).
● Use less for casual use.
● Enforce a 2-5% margin-of-error consensus to
reduce standard deviation.
Demonstration!
The End
Github: https://github.com/phpbench/phpbench
Readthedocs: https://phpbench.readthedocs.org/
Twitter: @phpbench @dantleech
Things we should take with us
● Wall time: Total (external) time taken.
● CPU time: CPU time taken.
● Microsecond: 1,000,000th of a second
● Mean: Average of a set of numbers.
● Standard Deviation (SD): Average deviation from the
mean between samples (kind of), often represented as
sigma (σ).
● Relative SD: As above but expressed as a percentage
(dimensionless quantity).
Outliers!

Mais conteúdo relacionado

Mais procurados

[데브루키] Color space gamma correction
[데브루키] Color space gamma correction[데브루키] Color space gamma correction
[데브루키] Color space gamma correctionMinGeun Park
 
Implementing imgui
Implementing imguiImplementing imgui
Implementing imguiHenryRose9
 
20121017_アプリ制作勉強会@GMO Yours
20121017_アプリ制作勉強会@GMO Yours20121017_アプリ制作勉強会@GMO Yours
20121017_アプリ制作勉強会@GMO YoursYozo SATO
 
08_게임 물리 프로그래밍 가이드
08_게임 물리 프로그래밍 가이드08_게임 물리 프로그래밍 가이드
08_게임 물리 프로그래밍 가이드noerror
 
カイゼン・ジャーニー・インセプションデッキ
カイゼン・ジャーニー・インセプションデッキカイゼン・ジャーニー・インセプションデッキ
カイゼン・ジャーニー・インセプションデッキtoshihiro ichitani
 
結果を出すリスティング広告の広告文の作り方
結果を出すリスティング広告の広告文の作り方結果を出すリスティング広告の広告文の作り方
結果を出すリスティング広告の広告文の作り方Keiji Abe
 
게임 레벨 디자인 - 강의 소개서
게임 레벨 디자인 - 강의 소개서게임 레벨 디자인 - 강의 소개서
게임 레벨 디자인 - 강의 소개서용태 이
 
優れたデザインの 定義と思考方法
優れたデザインの 定義と思考方法優れたデザインの 定義と思考方法
優れたデザインの 定義と思考方法Junichi Izumi
 
今どきの若手育成にひそむ3つの思いこみ
今どきの若手育成にひそむ3つの思いこみ今どきの若手育成にひそむ3つの思いこみ
今どきの若手育成にひそむ3つの思いこみMariko Hayashi
 
チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。
チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。 チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。
チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。 Yoshiki Hayama
 
プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!
プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!
プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!Yoshiki Hayama
 
Quartz 2D with Swift 3
Quartz 2D with Swift 3Quartz 2D with Swift 3
Quartz 2D with Swift 3Bob McCune
 
ブレインストーミングの技術(1DAYワークショップ)
ブレインストーミングの技術(1DAYワークショップ)ブレインストーミングの技術(1DAYワークショップ)
ブレインストーミングの技術(1DAYワークショップ)Rikie Ishii
 
あなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つける
あなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つけるあなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つける
あなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つけるYoshiki Hayama
 
KGC 2013 - 5일만에 레벨 디자인하기
KGC 2013 - 5일만에 레벨 디자인하기KGC 2013 - 5일만에 레벨 디자인하기
KGC 2013 - 5일만에 레벨 디자인하기용태 이
 
如何客製化URP渲染流程.pptx
如何客製化URP渲染流程.pptx如何客製化URP渲染流程.pptx
如何客製化URP渲染流程.pptxAkilarLiao
 
ペインストーミングで言葉の壁を越える
ペインストーミングで言葉の壁を越えるペインストーミングで言葉の壁を越える
ペインストーミングで言葉の壁を越えるshoji_yamada
 
ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템
ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템
ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템Chaeone Son
 
コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02
コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02
コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02INFOBAHN.inc(株式会社インフォバーン)
 

Mais procurados (20)

[데브루키] Color space gamma correction
[데브루키] Color space gamma correction[데브루키] Color space gamma correction
[데브루키] Color space gamma correction
 
Implementing imgui
Implementing imguiImplementing imgui
Implementing imgui
 
20121017_アプリ制作勉強会@GMO Yours
20121017_アプリ制作勉強会@GMO Yours20121017_アプリ制作勉強会@GMO Yours
20121017_アプリ制作勉強会@GMO Yours
 
08_게임 물리 프로그래밍 가이드
08_게임 물리 프로그래밍 가이드08_게임 물리 프로그래밍 가이드
08_게임 물리 프로그래밍 가이드
 
カイゼン・ジャーニー・インセプションデッキ
カイゼン・ジャーニー・インセプションデッキカイゼン・ジャーニー・インセプションデッキ
カイゼン・ジャーニー・インセプションデッキ
 
結果を出すリスティング広告の広告文の作り方
結果を出すリスティング広告の広告文の作り方結果を出すリスティング広告の広告文の作り方
結果を出すリスティング広告の広告文の作り方
 
게임 레벨 디자인 - 강의 소개서
게임 레벨 디자인 - 강의 소개서게임 레벨 디자인 - 강의 소개서
게임 레벨 디자인 - 강의 소개서
 
Tcvn 5674 1992
Tcvn 5674 1992Tcvn 5674 1992
Tcvn 5674 1992
 
優れたデザインの 定義と思考方法
優れたデザインの 定義と思考方法優れたデザインの 定義と思考方法
優れたデザインの 定義と思考方法
 
今どきの若手育成にひそむ3つの思いこみ
今どきの若手育成にひそむ3つの思いこみ今どきの若手育成にひそむ3つの思いこみ
今どきの若手育成にひそむ3つの思いこみ
 
チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。
チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。 チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。
チャットボットのUXと、導入現場のリアル:Webmaster Camp: 企業サイトの担当者が考えておきたい、AIとUIの今。
 
プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!
プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!
プロが生実演! 「ユーザーインタビュー」の深掘りテクニックを大公開!
 
Quartz 2D with Swift 3
Quartz 2D with Swift 3Quartz 2D with Swift 3
Quartz 2D with Swift 3
 
ブレインストーミングの技術(1DAYワークショップ)
ブレインストーミングの技術(1DAYワークショップ)ブレインストーミングの技術(1DAYワークショップ)
ブレインストーミングの技術(1DAYワークショップ)
 
あなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つける
あなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つけるあなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つける
あなたの手元の本よりいい方法がある! UXデザインのプロはこうやってユーザーのインサイトを確実に見つける
 
KGC 2013 - 5일만에 레벨 디자인하기
KGC 2013 - 5일만에 레벨 디자인하기KGC 2013 - 5일만에 레벨 디자인하기
KGC 2013 - 5일만에 레벨 디자인하기
 
如何客製化URP渲染流程.pptx
如何客製化URP渲染流程.pptx如何客製化URP渲染流程.pptx
如何客製化URP渲染流程.pptx
 
ペインストーミングで言葉の壁を越える
ペインストーミングで言葉の壁を越えるペインストーミングで言葉の壁を越える
ペインストーミングで言葉の壁を越える
 
ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템
ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템
ndc 2017 어쩌다 신입 - 초보 게임 개발자 2년 간의 포스트모템
 
コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02
コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02
コンテンツマーケティングの正しい活用方法 心を動かすオウンドメディアのつくり方 Ver.02
 

Destaque

Pair public final
Pair public finalPair public final
Pair public finalSammy Kibet
 
Sympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony CmsSympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony CmsJonathan Wage
 
Law firms and linked in 2012
Law firms and linked in 2012Law firms and linked in 2012
Law firms and linked in 2012wedu, Inc
 
Unidades Básicas de Saúde (UBS)
Unidades Básicas de Saúde (UBS)Unidades Básicas de Saúde (UBS)
Unidades Básicas de Saúde (UBS)Vagner Benites
 
Enbe future city template
Enbe future city templateEnbe future city template
Enbe future city templateALISON TANG
 
Laporan Percobaan Nernst Potensial
Laporan Percobaan Nernst PotensialLaporan Percobaan Nernst Potensial
Laporan Percobaan Nernst PotensialNurfaizatul Jannah
 
Interdependence Activity
Interdependence ActivityInterdependence Activity
Interdependence ActivityDarren Terry
 
Mindspeak Presentation - 18.03.16
Mindspeak Presentation - 18.03.16Mindspeak Presentation - 18.03.16
Mindspeak Presentation - 18.03.16Sammy Kibet
 
Energia especifica Arianna gonzalez2016
Energia especifica Arianna gonzalez2016Energia especifica Arianna gonzalez2016
Energia especifica Arianna gonzalez2016Annaira Rodriguez
 
Get started with docker &amp; dev ops
Get started with docker &amp; dev opsGet started with docker &amp; dev ops
Get started with docker &amp; dev opsAsya Dudnik
 
Chest x - ray
Chest   x - ray Chest   x - ray
Chest x - ray DR Laith
 

Destaque (16)

Mayan culture
Mayan cultureMayan culture
Mayan culture
 
Pair public final
Pair public finalPair public final
Pair public final
 
Sympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony CmsSympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony Cms
 
Caçambas
Caçambas  Caçambas
Caçambas
 
Law firms and linked in 2012
Law firms and linked in 2012Law firms and linked in 2012
Law firms and linked in 2012
 
Unidades Básicas de Saúde (UBS)
Unidades Básicas de Saúde (UBS)Unidades Básicas de Saúde (UBS)
Unidades Básicas de Saúde (UBS)
 
Enbe future city template
Enbe future city templateEnbe future city template
Enbe future city template
 
Laporan Percobaan Nernst Potensial
Laporan Percobaan Nernst PotensialLaporan Percobaan Nernst Potensial
Laporan Percobaan Nernst Potensial
 
Interdependence Activity
Interdependence ActivityInterdependence Activity
Interdependence Activity
 
Prayer points
Prayer pointsPrayer points
Prayer points
 
Mindspeak Presentation - 18.03.16
Mindspeak Presentation - 18.03.16Mindspeak Presentation - 18.03.16
Mindspeak Presentation - 18.03.16
 
Riscos 17 regioões
Riscos 17 regioõesRiscos 17 regioões
Riscos 17 regioões
 
Energia especifica Arianna gonzalez2016
Energia especifica Arianna gonzalez2016Energia especifica Arianna gonzalez2016
Energia especifica Arianna gonzalez2016
 
Get started with docker &amp; dev ops
Get started with docker &amp; dev opsGet started with docker &amp; dev ops
Get started with docker &amp; dev ops
 
ROBOTIC - Introduction to Robotics
ROBOTIC - Introduction to RoboticsROBOTIC - Introduction to Robotics
ROBOTIC - Introduction to Robotics
 
Chest x - ray
Chest   x - ray Chest   x - ray
Chest x - ray
 

Semelhante a Benchmarking and PHPBench

Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsMatt Warren
 
OSMC 2010 | NSClient++ - what's new? And what's coming! by Michael Medin
OSMC 2010 |  NSClient++ - what's new? And what's coming! by Michael MedinOSMC 2010 |  NSClient++ - what's new? And what's coming! by Michael Medin
OSMC 2010 | NSClient++ - what's new? And what's coming! by Michael MedinNETWAYS
 
Ruby3x3: How are we going to measure 3x
Ruby3x3: How are we going to measure 3xRuby3x3: How are we going to measure 3x
Ruby3x3: How are we going to measure 3xMatthew Gaudet
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Matt Warren
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Аліна Шепшелей
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"Inhacking
 
Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Tim Bunce
 
Velocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing SystemsVelocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing SystemsSOASTA
 
Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)SOASTA
 
Matheus Albuquerque "The best is yet to come: the Future of React"
Matheus Albuquerque "The best is yet to come: the Future of React"Matheus Albuquerque "The best is yet to come: the Future of React"
Matheus Albuquerque "The best is yet to come: the Future of React"Fwdays
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularErik Guzman
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartChen Fisher
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Scott Keck-Warren
 
Puppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollective
Puppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollectivePuppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollective
Puppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollectivePuppet
 
.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET
.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET
.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NETNETFest
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD WorkshopWolfram Arnold
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestPavan Chitumalla
 

Semelhante a Benchmarking and PHPBench (20)

Dutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: DistilledDutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: Distilled
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-Optimisations
 
OSMC 2010 | NSClient++ - what's new? And what's coming! by Michael Medin
OSMC 2010 |  NSClient++ - what's new? And what's coming! by Michael MedinOSMC 2010 |  NSClient++ - what's new? And what's coming! by Michael Medin
OSMC 2010 | NSClient++ - what's new? And what's coming! by Michael Medin
 
Ruby3x3: How are we going to measure 3x
Ruby3x3: How are we going to measure 3xRuby3x3: How are we going to measure 3x
Ruby3x3: How are we going to measure 3x
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
 
Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406Devel::NYTProf v5 at YAPC::NA 201406
Devel::NYTProf v5 at YAPC::NA 201406
 
Velocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing SystemsVelocity 2015: Building Self-Healing Systems
Velocity 2015: Building Self-Healing Systems
 
Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)Velocity 2015 building self healing systems (slide share version)
Velocity 2015 building self healing systems (slide share version)
 
Matheus Albuquerque "The best is yet to come: the Future of React"
Matheus Albuquerque "The best is yet to come: the Future of React"Matheus Albuquerque "The best is yet to come: the Future of React"
Matheus Albuquerque "The best is yet to come: the Future of React"
 
Javascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & AngularJavascript Memory leaks and Performance & Angular
Javascript Memory leaks and Performance & Angular
 
Functional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smartFunctional programming with Ruby - can make you look smart
Functional programming with Ruby - can make you look smart
 
Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)Developing a Culture of Quality Code (Midwest PHP 2020)
Developing a Culture of Quality Code (Midwest PHP 2020)
 
Puppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollective
Puppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollectivePuppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollective
Puppet Camp DC 2015: Distributed OpenSCAP Compliance Validation with MCollective
 
.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET
.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET
.NET Fest 2019. Николай Балакин. Микрооптимизации в мире .NET
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 

Mais de dantleech

2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphpdantleech
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...dantleech
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
Phpactor and VIM
Phpactor and VIMPhpactor and VIM
Phpactor and VIMdantleech
 
A Tale of Three Components
A Tale of Three ComponentsA Tale of Three Components
A Tale of Three Componentsdantleech
 
Boltc CMS - a really quick overview
Boltc CMS - a really quick overviewBoltc CMS - a really quick overview
Boltc CMS - a really quick overviewdantleech
 
Tmux quick intro
Tmux quick introTmux quick intro
Tmux quick introdantleech
 

Mais de dantleech (8)

2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
Building and Incredible Machine with Pipelines and Generators in PHP (IPC Ber...
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
Phpactor and VIM
Phpactor and VIMPhpactor and VIM
Phpactor and VIM
 
A Tale of Three Components
A Tale of Three ComponentsA Tale of Three Components
A Tale of Three Components
 
Boltc CMS - a really quick overview
Boltc CMS - a really quick overviewBoltc CMS - a really quick overview
Boltc CMS - a really quick overview
 
Tmux quick intro
Tmux quick introTmux quick intro
Tmux quick intro
 

Último

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Último (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

Benchmarking and PHPBench

  • 1. Benchmarking, Statistics & PHPBench A framework for creating glorious benchmarks by Daniel Leech @dantleech @phpbench
  • 2. About Me ● Daniel Leech ● PHP Developer – Symfony CMF and associated projects ● PHPCR-ODM, Jackalope, PHPCR – Sulu CMF – PHPBench ● Cycle tourer
  • 4. SCPT ● Testing: Running an operation and obtaining a result. ● Performance: We are concerned about the performance of the subject. ● Comparative: Ultimately, we are always concerned about the performance of one thing as compared to another thing. ● Standardized: The tests should be standardized so that they can be applied meaningfully to all subjects.
  • 5. Differences to Profiling Benchmarking Profiling Measures External wall time Internal call times Observer effect? Minimal Major Scope (typical) Scenario Request Applies to (typical) Libraries Applications
  • 6. Benchmarking Script <?php $a = array(); $start = microtime( true ); for ($i = 0; $i < 10000; ++$i) { isset($a['key']); } $total_time = microtime( true ) - $start; echo "Total time: ", number_format($total_time, 6), PHP_EOL; $start = microtime( true ); for ($i = 0; $i < 10000; ++$i) { in_array('key', $a); } $total_time = microtime( true ) - $start; echo "Total time: ", number_format($total_time, 6), PHP_EOL; http://stackoverflow.com/questions/13483219/what-is-faster-in-array-or-isset found in the wild
  • 7. Issues ● Boilerplate code. ● Relies on single samples. ● Results are not persisted. ● Not scalable.
  • 8. Benchmarking Framework Should ● Execute code units. ● Perform tests multiple times to verify results. ● Provide visual feedback. ● Perform statistical analysis. ● Be able to serialize and store results.
  • 10. Revolutions Number of times we consecutively execute our benchmark subject. <?php $revolutions = 10000; for ($i =0; $i < $revolutions; $i++) { // do something }
  • 11. Iterations Each iteration records the time taken to execute the revolutions. <?php $iterations = 100; $revolutions = 10000; $results = []; for ($iteration = 0; $iteration < $iterations; $iteration++) { $startTime = microtime(true); for ($rev = 0; $rev < $revolultions; $rev++) { // do something } $time = microtime(true) - $startTime; $times[] = $time; } illustrative example
  • 12. Subjects The actual code we are benchmarking. Subjects could be: – PHP internal functions. – User functions (think unit tests). – User services (think functional tests). – External services. – Anything you can wrap in a function.
  • 13. Subjects <?php isset($a['b']); <?php $pdoConnection->query(“SELECT * FROM foo”); <?php $container->get('some.service'); <?php $guzzle->get('https://github.com/phpbench/phpbench'); Algorithms External services User libraries HTTP
  • 14. Benchmarking with PHPBench PHPBench is a command line based benchmarking tool similar to PHPUniut. $ phpbench phpbench version 0.10.0-dev Usage: command [options] [arguments] ... Available commands: help Displays help for a command list Lists commands report Generate a report from an XML file run Run benchmarks
  • 15. Benchmark Class ● Class name suffixed with “Bench”. ● Subject prefixed with “bench”. ● Does not know about PHPBench. <?php class HashBench { public function benchHash() { md5('hello world'); } } HashBench.php actual working example!
  • 16. Benchmark Class ● Annotations determine how the subject is executed. ● Class and/or method level. ● Aware of class inheritance. <?php class HashBench { /** * @Revs(10000) * @Iterations(100) */ public function benchHash() { md5('hello world'); } } HashBench.php
  • 17. Running Benchmarks $ phpbench run HashBench.php PhpBench 0.9.0-dev. Running benchmarks. HashBench benchHash I9 P0 μ/r: 1.716μs μSD/r 0.099μs μRSD/r: 5.77% 1 subjects, 10 iterations, 0 revs, 0 rejects (min mean max) = 1.567 1.716 1.887 (μs) ⅀T: 17.160μs μSD/r 0.099μs μRSD/r: 5.772% I: Iteration # P: Parameter set # /r: Times are divided by number of revolutions. μ: Mean (average). μs: Microseconds. ⅀T: Total time. SD: Standard deviation. RSD: Relative standard deviation.
  • 18. Running Benchmarks $ phpbench run HashBench.php PhpBench 0.9.0-dev. Running benchmarks. HashBench benchHash I9 P0 μ/r: 1.716μs μSD/r 0.099μs μRSD/r: 5.77% 1 subjects, 10 iterations, 0 revs, 0 rejects (min mean max) = 1.567 1.716 1.887 (μs) ⅀T: 17.160μs μSD/r 0.099μs μRSD/r: 5.772% ● Progress loggers provide realtime feedback. ● Specified with --progress ● Reports can also be generated.
  • 20. Revolutions <?php $revolutions = 10000; $start = microtime(true); for ($i =0; $i < $revolutions; $i++) { md5('hello world'); } $elapsed = microtime(true) - $start; How do revolutions affect time?
  • 21. Revolutions <?php $time = $iterationTime / $revolutions; Reported time is total time divided by number of revolutions. Answers the question: What is the average execution time of the method?
  • 22. Revolutions Time (µs/r) 1 10 100% 2 6 60% 4 3.75 37.5% 8 2.625 26.2% 16 2.188 21.8% 32 1.969 19.6% 64 1.75 17.5% 10,000 1.72 17.2% Micro Revolutionary Effect ● Includes microtime and loop calls. ● Begins to stabilise at ~32 revolutions. ● Regression to ~17% of first value. Micro (microseconds) benchmarks are heavily affected by the number of revolutions.
  • 23.
  • 24. Revolutions Time (ms/r) 1 512 100% 2 407 79% 4 381 74% 8 375 73% 16 408 79% 32 369 72% 64 367 71% Macro Revolutionary Effect ● Warmup factor (autoload cache, etc) ● Earlier stabilisation. ● Regression to 71% of first value. Macro (milliseconds, seconds) benchmarks less affected.
  • 25.
  • 26. Iterations <?php class HashBench { /** * @Revs(10000) * @Iterations(100) */ public function benchHash() { md5('hello world'); } } ● Each iteration provides a time measurement. ● Iterations produce a range of different time measurements.
  • 27. Iterations Iteration μ Time (μs) 1 2.766 2 2.773 3 2.737 4 2.782 5 2.776 6 2.716 7 2.729 .. ..
  • 28.
  • 30. Normal Distribution ● Applies to any set of random variables with an Expected Value. ● Benchmark times should be normally distributed. ● Peak is the most probable time.
  • 31.
  • 32.
  • 33.
  • 35. The Mean and the Mode Mean: Average value of the set: Mode: Most common value in the set...
  • 38. Standard Deviation (SD) ● Unit represented as “sigma” σ ● Almost the average distance between values in the set. ● An SD of zero indicates that all the values are identical. ● Relative standard deviation (RSD) is the SD divided by the mean. It is a percentage. ● RSD provides a comparable number.
  • 39. Standard Deviation | RSD = 3% MEAN = 2.078 MIN = 2.5 MAX = 3.2
  • 40. Standard Deviation RSD = 30% MEAN = 3.440 MIN = 2 MAX = 6
  • 41. Standard Deviation RSD = 11% MEAN = 2.793 MIN = 2.5 MAX = 4.5
  • 43. Shutdown Unecessary Stuff ● No music processes. ● No video processes. ● No Grand Theft Aauto.
  • 44. Retry Threshold Keep running the iteration set until all times fall into a given margin of error (MOE). ● Feature of PHPBench ● Retries iterations when they fall outside of the MOE. phpbench run examples/HashBench.php --retry-threshold=2
  • 45. RSD: 5.7% 16% retry threshold
  • 46. RSD: 1.9% 4% retry threshold
  • 47. RSD: < 1% 2% retry threshold
  • 48. Take Away ● Use a large number of revolutions for micro benchmarks (at least 1000). ● For best results use a large number of Iterations (100-500). ● Use less for casual use. ● Enforce a 2-5% margin-of-error consensus to reduce standard deviation.
  • 50. The End Github: https://github.com/phpbench/phpbench Readthedocs: https://phpbench.readthedocs.org/ Twitter: @phpbench @dantleech
  • 51.
  • 52. Things we should take with us ● Wall time: Total (external) time taken. ● CPU time: CPU time taken. ● Microsecond: 1,000,000th of a second ● Mean: Average of a set of numbers. ● Standard Deviation (SD): Average deviation from the mean between samples (kind of), often represented as sigma (σ). ● Relative SD: As above but expressed as a percentage (dimensionless quantity).
  • 53.
  • 54.