<?php /** * Part of Windwalker project. * * @copyright Copyright (C) 2014 {ORGANIZATION}. All rights reserved. * @license GNU Lesser General Public License version 2.1 or later. */ include_once __DIR__ . '/../../../vendor/autoload.php'; $benchmark = new \Windwalker\Profiler\Benchmark(); class Test { public function f1() { md5(uniqid()); } public static function f2() { sha1(uniqid()); } } $f1 = function () { $t = new Test(); $t->f1(); }; $f2 = function () { Test::f2(); }; echo $benchmark->setTimeFormat(\Windwalker\Profiler\Benchmark::MICRO_SECOND)->addTask('test1', $f1)->addTask('test2', $f2)->execute(10000)->render(6, 'asc');
include_once __DIR__ . '/../../../vendor/autoload.php'; use Windwalker\Router\Route; $routes = file_get_contents(__DIR__ . '/fixtures/routes.txt'); $routes = explode("\n", trim($routes)); $routeItems = array_map(function ($route) { $route = trim($route, '/'); return new Route($route, $route, array('_return' => $route)); }, $routes); $count = count($routes); $seq = new \Windwalker\Router\Matcher\SequentialMatcher(); $seq->setRoutes($routeItems)->setDebug(false); $trie = new \Windwalker\Router\Matcher\TrieMatcher(); $trie->setRoutes($routeItems)->setDebug(false); $bin = new \Windwalker\Router\Matcher\BinaryMatcher(); $bin->setRoutes($routeItems)->setDebug(false); $bench = new \Windwalker\Profiler\Benchmark(); $avg = array(); $bench->addTask('Sequential', function () use($seq, $routes, $count, &$avg) { static $i = 0; if ($i + 1 > $count) { $i = 0; } $r = $seq->match($routes[$i]); if ($r->getName() == trim($routes[$i], '/')) { echo '.'; $avg['seq'] += $seq->getCount(); } $i++; }); $bench->addTask('Binary', function () use($bin, $routes, $count, &$avg) { static $i = 0;