示例#1
0
<?php

require 'SimpleBench/Task.php';
require 'SimpleBench/Utils.php';
require 'SimpleBench/ComparisonMatrix.php';
require 'SimpleBench/SystemInfo/Darwin.php';
require 'SimpleBench/MatrixWriter/Writer.php';
require 'SimpleBench/MatrixWriter/JsonWriter.php';
require 'SimpleBench/MatrixPrinter/EzcGraph.php';
require 'SimpleBench/MatrixPrinter/Console.php';
require 'SimpleBench.php';
// requirement from symfon
require '../src/Pux/PatternCompiler.php';
use Pux\Mux;
$mux = Pux\Mux::__set_state(array('id' => NULL, 'routes' => array(0 => array(0 => false, 1 => '/hello', 2 => array(0 => 'HelloController', 1 => 'helloAction'), 3 => array())), 'routesById' => array(), 'staticRoutes' => array(), 'submux' => array(), 'expand' => true));
/* version */
$bench = new SimpleBench();
$bench->setN(10000);
$bench->iterate('match', function () use($mux) {
    $route = $mux->match('/hello');
});
$bench->iterate('dispatch', function () use($mux) {
    $route = $mux->dispatch('/hello');
});
$bench->iterate('__set_state', function () {
    $mux = Pux\Mux::__set_state(array('id' => NULL, 'routes' => array(0 => array(0 => false, 1 => '/hello', 2 => array(0 => 'HelloController', 1 => 'helloAction'), 3 => array())), 'routesById' => array(), 'staticRoutes' => array(), 'submux' => array(), 'expand' => true));
    /* version */
});
$result = $bench->compare();
echo $result->output('console');
require 'SimpleBench/MatrixWriter/Writer.php';
require 'SimpleBench/MatrixWriter/JsonWriter.php';
require 'SimpleBench/MatrixPrinter/EzcGraph.php';
require 'SimpleBench/MatrixPrinter/Console.php';
require 'SimpleBench/SystemInfo/Darwin.php';
require 'SimpleBench.php';
// requirement from symfon
require 'symfony/vendor/autoload.php';
require 'pux/PatternCompiler.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Pux\Mux;
$bench = new SimpleBench();
$bench->setN(5000);
$mux = new Mux();
$mux->add('/product/:id', ['ProductController', 'index']);
$bench->iterate('pux extension (dispatch)', function () use($mux) {
    $route = $mux->dispatch('/product/23');
});
$routes = new RouteCollection();
$routes->add('product', new Route('/product/{id}', array('controller' => 'foo', 'action' => 'bar')));
$bench->iterate('symfony/routing (dispatch)', function () use($routes) {
    $context = new RequestContext();
    // this is optional and can be done without a Request instance
    $context->fromRequest(Request::createFromGlobals());
    $matcher = new UrlMatcher($routes, $context);
    $route = $matcher->match('/product/23');
});
示例#3
0
<?php

require 'tests/bootstrap.php';
require 'tests/tests/Author.php';
$bench = new SimpleBench();
$bench->setN(500000);
$bench->setTitle('obj create');
$bench->iterate('obj create', 'object construction time', function () {
    $s = new stdClass();
});
$bench->iterate('model create', 'model create', function () {
    $a = new TestApp\Author();
});
$result = $bench->compare();
echo $result->output('console');
示例#4
0
<?php

require 'tests/bootstrap.php';
#  $pdo = new PDO('mysql:host=localhost;dbname=benchmarks', 'root', '123123' );
#  $mysqli = new mysqli("localhost", "root", "123123", "benchmarks");
$driver = new SQLBuilder\Driver();
$driver->configure('driver', 'pgsql');
$driver->configure('quote_table', true);
$driver->configure('quote_column', true);
$driver->configure('trim', true);
$driver->configure('placeholder', 'named');
$sb = new SQLBuilder\QueryBuilder();
$sb->driver = $driver;
$bench = new SimpleBench(array('gc' => 1));
$bench->n = 1000;
$bench->title = 'sql builder';
$bench->iterate('select', 'select', function () use($sb) {
    $sb->select('*')->table('users')->alias('u')->build();
});
$bench->iterate('join', 'join', function () use($sb) {
    $sb->select('*')->table('users')->alias('u')->join('tweets')->alias('t')->on()->equal('u.id', array('t.user_id'))->back()->build();
});
$result = $bench->compare();
echo $result->output('console');
示例#5
0
文件: bench.php 项目: c9s/roller
}
require '../vendor/pear/Universal/ClassLoader/BasePathClassLoader.php';
$loader = new \Universal\ClassLoader\BasePathClassLoader(array('../src', '../vendor/pear', '/opt/local/lib/php'));
$loader->useIncludePath(true);
$loader->register();
echo "init router\n";
$router = new Roller\Router();
$router->add('/', function () {
    return 'Hello World, please request /=/test for RESTful resource handler demo.';
});
foreach (range(1, 1000) as $i) {
    $router->add('/foo' . $i, function () {
        return 'bar';
    });
}
$router->routes->compile();
// var_dump( $router->routes->routes );
echo "dispatching\n";
$b = new SimpleBench();
$b->setN(10);
$b->iterate('roller_ext', 'roller_ext', function () use($router) {
    $r = roller_dispatch($router->routes->routes, '/foo1000');
});
$router->enableExtension = false;
$b->iterate('roller', 'roller', function () use($router) {
    $r = $router->dispatch('/foo1000');
});
// var_dump( $r , $regs );
// var_dump( hello_array_value( array(  'foo' => 'what' ) , 'foo' ) );
$result = $b->compare();
echo $result->output('Console');
require 'SimpleBench/MatrixWriter/Writer.php';
require 'SimpleBench/MatrixWriter/JsonWriter.php';
require 'SimpleBench/MatrixPrinter/EzcGraph.php';
require 'SimpleBench/MatrixPrinter/Console.php';
require 'SimpleBench/SystemInfo/Darwin.php';
require 'SimpleBench.php';
// requirement from symfon
require 'symfony/vendor/autoload.php';
require 'pux/PatternCompiler.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use pux\Mux;
$bench = new SimpleBench();
$bench->setN(10000);
$bench->iterate('pux extension', function () {
    $mux = (require 'pux/hello_mux.php');
    $route = $mux->dispatch('/hello');
});
$bench->iterate('symfony/routing', function () {
    $routes = new RouteCollection();
    $routes->add('hello', new Route('/hello', array('controller' => 'foo', 'action' => 'bar')));
    $context = new RequestContext();
    // this is optional and can be done without a Request instance
    $context->fromRequest(Request::createFromGlobals());
    $matcher = new UrlMatcher($routes, $context);
    $route = $matcher->match('/hello');
});
$result = $bench->compare();
require 'SimpleBench/MatrixPrinter/EzcGraph.php';
require 'SimpleBench/MatrixPrinter/Console.php';
require 'SimpleBench/SystemInfo/Darwin.php';
require 'SimpleBench.php';
// requirement from symfon
require 'symfony/vendor/autoload.php';
require 'pux/pux/vendor/autoload.php';
require 'klein/vendor/autoload.php';
require 'ham/ham/ham/ham.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Pux\Mux;
$bench = new SimpleBench();
$bench->setN(10000);
// plain php dispatch function
$phparray = array('/hello' => array('hello'));
function phparray_dispatch($path)
{
    global $phparray;
    if (isset($phparray[$path])) {
        return $phparray[$path];
    }
    foreach ($phparray as $pattern => $route) {
        if (preg_match('#' . $pattern . '#', $path)) {
            return $route;
        }
    }
}