Skip to content

@igorw /bench.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?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);
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.