-
-
Save sanis/512dd7e6ffd153305808cc84414a443e to your computer and use it in GitHub Desktop.
| <?php | |
| /** | |
| * composer require phpbench/phpbench | |
| * php vendor/bin/phpbench run CachingBench.php --report=default | |
| */ | |
| /* | |
| PhpBench 0.13.0. Running benchmarks. | |
| \CachingBench | |
| benchGetFileCaching I49 P0 [μ Mo]/r: 0.034 0.031 (ms) [μSD μRSD]/r: 0.005ms 15.97% | |
| benchGetIgbinaryFileCaching I49 P0 [μ Mo]/r: 0.025 0.024 (ms) [μSD μRSD]/r: 0.004ms 17.77% | |
| benchGetRamFileCaching I49 P0 [μ Mo]/r: 0.029 0.028 (ms) [μSD μRSD]/r: 0.001ms 4.15% | |
| benchGetIgbinaryRamFileCachingI49 P0 [μ Mo]/r: 0.023 0.022 (ms) [μSD μRSD]/r: 0.001ms 3.14% | |
| benchGetRedisCaching I49 P0 [μ Mo]/r: 0.127 0.144 (ms) [μSD μRSD]/r: 0.032ms 24.97% | |
| benchGetIgbinaryRedisCaching I49 P0 [μ Mo]/r: 0.138 0.146 (ms) [μSD μRSD]/r: 0.039ms 28.24% | |
| benchGetPlainRedisCaching I49 P0 [μ Mo]/r: 0.099 0.110 (ms) [μSD μRSD]/r: 0.021ms 21.21% | |
| 7 subjects, 350 iterations, 70,000 revs, 0 rejects | |
| (best [mean mode] worst) = 21.829 [67.636 72.267] 25.374 (μs) | |
| ⅀T: 23,672.437μs μSD/r 14.747μs μRSD/r: 16.492% | |
| */ | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\BeforeClassMethods({"initOxidThings"}) | |
| */ | |
| class CachingBench | |
| { | |
| public static $redis; | |
| public static function getRedis() | |
| { | |
| if (self::$redis) { | |
| return self::$redis; | |
| } else { | |
| $redis = new \Redis(); | |
| $redis->connect('redis', 6379); | |
| self::$redis = $redis; | |
| } | |
| return self::$redis; | |
| } | |
| /** | |
| * Inits the files and puts to databases | |
| */ | |
| public static function initOxidThings() | |
| { | |
| // get from database | |
| include_once __DIR__ . '/http/bootstrap.php'; | |
| $config = oxRegistry::getConfig(); | |
| $category = oxNew('oxCategory'); | |
| $category->load('cxmCID2557884'); | |
| file_put_contents('test.txt', serialize($category)); | |
| file_put_contents('test2.txt', igbinary_serialize($category)); | |
| file_put_contents('/dev/shm/test.txt', serialize($category)); | |
| file_put_contents('/dev/shm/test2.txt', igbinary_serialize($category)); | |
| $redis = self::getRedis(); | |
| $redis->flushAll(); | |
| $redis->set('test', serialize($category)); | |
| $redis->set('test2', igbinary_serialize($category)); | |
| $redis->set('test3', $category); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetFileCaching() | |
| { | |
| $fileContents = file_get_contents('test.txt'); | |
| $category = unserialize($fileContents); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetIgbinaryFileCaching() | |
| { | |
| $fileContents = file_get_contents('test2.txt'); | |
| $category = igbinary_unserialize($fileContents); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetRamFileCaching() | |
| { | |
| $fileContents = file_get_contents('/dev/shm/test.txt'); | |
| $category = unserialize($fileContents); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetIgbinaryRamFileCaching() | |
| { | |
| $fileContents = file_get_contents('/dev/shm/test2.txt'); | |
| $category = igbinary_unserialize($fileContents); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetRedisCaching() | |
| { | |
| $redis = self::getRedis(); | |
| $contents = $redis->get('test'); | |
| $category = unserialize($contents); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetIgbinaryRedisCaching() | |
| { | |
| $redis = self::getRedis(); | |
| $contents = $redis->get('test2'); | |
| $category = igbinary_unserialize($contents); | |
| } | |
| /** | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Revs(10000) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\Iterations(50) | |
| * @\PhpBench\Benchmark\Metadata\Annotations\OutputTimeUnit("milliseconds", precision=3) | |
| */ | |
| public function benchGetPlainRedisCaching() | |
| { | |
| $redis = self::getRedis(); | |
| $category = $redis->get('test3'); | |
| } | |
| } |
-bash-4.3$ php vendor/bin/phpbench run CachingBench.php --output=markdown --progress=histogram --iterations=100 --revs=10000 --sleep=10000
PhpBench 0.13.0. Running benchmarks.
\CachingBench
#0 benchGetFileCaching,
#1 benchGetIgbinaryFileCaching,
#2 benchGetRamFileCaching,
#3 benchGetIgbinaryRamFileCaching,
#4 benchGetRedisCaching,
#5 benchGetIgbinaryRedisCaching,
#6 benchGetPlainRedisCaching
#0 (σ = 0.639μs ) -2σ [ ▁▁▅█▅▅▅▃█▄▄▃▂▁▂ ] +2σ [μ Mo]/r: 0.029 0.029 μRSD/r: 2.20%
#1 (σ = 0.510μs ) -2σ [▁▁▂▂▃▄▅█▂▅▃▂▂▁▁▁ ] +2σ [μ Mo]/r: 0.024 0.024 μRSD/r: 2.15%
#2 (σ = 0.945μs ) -2σ [ ▁▂▅▇█▇▅▂▂▃▂▁▁ ] +2σ [μ Mo]/r: 0.029 0.028 μRSD/r: 3.28%
#3 (σ = 0.678μs ) -2σ [ ▁▂▂▄▇▆█▄▆▂▃▃ ▁] +2σ [μ Mo]/r: 0.023 0.023 μRSD/r: 2.96%
#4 (σ = 27.478μs ) -2σ [ █▃▂▂▃▂▂▂▃▅▁ ] +2σ [μ Mo]/r: 0.118 0.092 μRSD/r: 23.19%
#5 (σ = 26.689μs ) -2σ [ █▂▁▁▁▁▂▁▅▄▁▁▁ ] +2σ [μ Mo]/r: 0.112 0.138 μRSD/r: 23.86%
#6 (σ = 16.868μs ) -2σ [▁▂▂▂▂▄▃▄▂▃▄█▃▂▁ ] +2σ [μ Mo]/r: 0.099 0.112 μRSD/r: 16.99%
7 subjects, 700 iterations, 70,000 revs, 0 rejects
(best [mean mode] worst) = 21.789 [62.018 63.546] 26.034 (μs)000 rev(s),
⅀T: 43,412.758μs μSD/r 10.544μs μRSD/r: 10.661%
7 subjects, 700 iterations, 70,000 revs, 0 rejects
(best [mean mode] worst) = 21.559 [60.501 66.873] 25.659 (μs)
⅀T: 42,350.413μs μSD/r 10.091μs μRSD/r: 14.131%
PHPBench Benchmark Results
suite: 133c7d14205628aea2feb4d20e09b7619c1cafc9, date: 2017-07-05, stime: 18:34:25