Created
April 21, 2013 12:16
-
-
Save igorw/5429404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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