public
Created

  • Download Gist
bench.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
<?php
 
require 'vendor/autoload.php';
 
function inc($x) {
return $x + 1;
}
 
function mul2($x) {
return $x * 2;
}
 
define('ITERATIONS', 100000);
 
// ---
 
echo "compose without creation\n";
$composed = igorw\compose('mul2', 'inc');
$start = microtime(true);
 
for ($i = 0; $i < ITERATIONS; $i++) {
$composed($i);
}
 
printf("%s ms\n", (microtime(true)-$start)*1000);
echo "---\n";
gc_collect_cycles();
 
// ---
 
echo "compose with creation\n";
$start = microtime(true);
 
for ($i = 0; $i < ITERATIONS; $i++) {
$composed = igorw\compose('mul2', 'inc');
$composed($i);
}
 
printf("%s ms\n", (microtime(true)-$start)*1000);
echo "---\n";
gc_collect_cycles();
 
// ---
 
echo "pipeline without creation\n";
$composed = igorw\pipeline('inc', 'mul2');
$start = microtime(true);
 
for ($i = 0; $i < ITERATIONS; $i++) {
$composed($i);
}
 
printf("%s ms\n", (microtime(true)-$start)*1000);
echo "---\n";
gc_collect_cycles();
 
// ---
 
echo "pipeline with creation\n";
$start = microtime(true);
 
for ($i = 0; $i < ITERATIONS; $i++) {
$composed = igorw\pipeline('inc', 'mul2');
$composed($i);
}
 
printf("%s ms\n", (microtime(true)-$start)*1000);
echo "---\n";
gc_collect_cycles();
 
// ---
 
echo "raw\n";
$start = microtime(true);
 
for ($i = 0; $i < ITERATIONS; $i++) {
mul2(inc($i));
}
 
printf("%s ms\n", (microtime(true)-$start)*1000);
results.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14
compose without creation
652.48799324036 ms
---
compose with creation
1575.2029418945 ms
---
pipeline without creation
664.56484794617 ms
---
pipeline with creation
2157.4680805206 ms
---
raw
167.42491722107 ms

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.