// a simple function
    return $x + 1;
}
class clsTest
{
    function method($x)
    {
        // a simple method
        return $x + 1;
    }
    static function static_method($x)
    {
        // a simple method
        return $x + 1;
    }
}
$obj = new clsTest();
$x = 29;
$params = array(&$obj, $x);
$benchmark = new Benchmark('bench function Vs method');
$benchmark->setRunningCount(10000);
$result1 = $benchmark->run('global function', 'f_function_normal', $params);
$result2 = $benchmark->run('object method', 'f_method_normal', $params);
$result3 = $benchmark->run('static object method', 'f_method_static', $params);
$result4 = $benchmark->run('static object method as normal', 'f_method_static_as_normal', $params);
$benchmark->compare($result1, $result2);
$benchmark->compare($result1, $result3);
$benchmark->compare($result1, $result4);
$benchmark->compare($result2, $result3);
$benchmark->compare($result3, $result4);
$benchmark->showResults();
Exemplo n.º 2
0
        $m = array();
        for ($i = 2; $i <= 8; $i *= 2) {
            $t = 32 / $i;
            echo "<b>Singular value decomposition: {$t} random {$i}x{$i} matrices</b><br />";
            $s = $benchmark->displayStats($benchmark->runSVD($i, $t));
            $m[$i] = $s['mean'];
            echo "<br />";
        }
        echo '<pre>';
        foreach ($m as $x => $y) {
            echo "{$x}\t" . 1000 * $y . "\n";
        }
        echo '</pre>';
        break;
    case 'all':
        $s = $benchmark->run();
        print "<br /><b>Total<b>: {$s}s<br />";
        break;
    default:
        ?>
	<ul>
	<li><a href="benchmark.php?decomposition=all">Complete Benchmark</a></li>
	<ul>
	<li><a href="benchmark.php?decomposition=cholesky">Cholesky</a></li>
	<li><a href="benchmark.php?decomposition=eigenvalue">Eigenvalue</a></li>
	<li><a href="benchmark.php?decomposition=lu">LU</a></li>
	<li><a href="benchmark.php?decomposition=qr">QR</a></li>
	<li><a href="benchmark.php?decomposition=svd">Singular Value</a></li>
	</ul>
	</ul>
	<?php 
Exemplo n.º 3
0
            }
            $profiler->leaveSection($test);
        }
        $profiler->stop();
        $profiler->display();
    }
    protected function configDecodeBinarySimple()
    {
        return array(new Protobuf\Codec\Binary(), file_get_contents(__DIR__ . '/protos/simple.bin'));
    }
    protected function runDecodeBinarySimple($codec, $data)
    {
        $codec->decode(new test\Simple(), $data);
    }
    protected function configDecodeJsonSimple()
    {
        $codecBin = new Protobuf\Codec\Binary();
        $codecJson = new Protobuf\Codec\Json();
        $bin = $this->configDecodeBinarySimple();
        $simple = $codecBin->decode(new test\Simple(), $bin[1]);
        $data = $codecJson->encode($simple);
        return array($codecJson, $data);
    }
    protected function runDecodeJsonSimple($codec, $data)
    {
        $codec->decode(new test\Simple(), $data);
    }
}
$bench = new Benchmark();
$bench->run(1000);
Exemplo n.º 4
0
<?php

require __DIR__ . '/../benchmark.php';
$vector = new Icecave\Collections\Vector();
Benchmark::run(1000, function ($i) use($vector) {
    $vector->pushFront($i);
}, function ($i) use($vector) {
    $vector->popFront();
});
Exemplo n.º 5
0
<?php

require __DIR__ . '/../benchmark.php';
$vector = new Icecave\Collections\Vector();
Benchmark::run(50000, null, function ($i) use($vector) {
    $vector->pushBack($i);
});
Exemplo n.º 6
0
        $container = new Container($framework);
        $container->run();
    }
} else {
    if ($command == ArgParser::CMD_STOP) {
        Container::checkDocker();
        foreach (Framework::getFrameworks() as $framework) {
            $container = new Container($framework);
            $container->stop();
        }
    } else {
        if ($command == ArgParser::CMD_BENCHMARK) {
            out("Doing " . Benchmark::NUMBER_OF_CALLS . " calls per framework. Displaying averages.");
            foreach (Framework::getFrameworks() as $framework) {
                $benchmark = new Benchmark($framework);
                $benchmark->run()->outputTimes();
            }
        } else {
            out("== Available commands: ==");
            out(ArgParser::CMD_BENCHMARK);
            out(ArgParser::CMD_START);
            out(ArgParser::CMD_STOP);
        }
    }
}
class Container
{
    /** @var Framework */
    private $framework;
    /** @var string */
    private $directory;
Exemplo n.º 7
0
    }
    protected function classify($index)
    {
        $closest_neighbour_index = null;
        $closest_neighbour_distance = INF;
        $count = count($this->attributes);
        for ($i = 0; $i < $count; $i++) {
            if ($i == $index) {
                continue;
            }
            $total = 0;
            for ($j = 0; $j < 3; $j++) {
                $total += pow($this->attributes[$index][$j] - $this->attributes[$i][$j], 2);
            }
            $distance = sqrt($total);
            if ($distance < $closest_neighbour_distance) {
                $closest_neighbour_index = $i;
                $closest_neighbour_distance = $distance;
            }
        }
        return $this->classes[$closest_neighbour_index];
    }
}
if (defined('HHVM_VERSION')) {
    echo 'HHVM' . PHP_EOL;
} else {
    echo 'PHP ' . PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . PHP_EOL;
}
$benchmark = new Benchmark();
$total = $benchmark->run();
echo number_format($total) . ' instances classified in 30 seconds (' . number_format($total / 30) . ' per second)' . PHP_EOL;
<?php

include dirname(__FILE__) . '/include/Benchmark.php';
function f_test_keyexists($prms)
{
    return array_key_exists('thekey', $prms);
}
function f_test_isset($prms)
{
    return isset($prms['thekey']);
}
$benchmark = new Benchmark('bench isset() Vs array_key_exists()');
$benchmark->setRunningCount(10000);
$params_without = array('param1' => 'value1', 'name' => 'Paul', 'id=' > 23);
$params_with = array('param1' => 'value1', 'name' => 'Paul', 'thekey' => 'here', 'id=' > 23);
$result1 = $benchmark->run('array_key_exists() with existing key', 'f_test_keyexists', array($params_with));
$result2 = $benchmark->run('array_key_exists() with non existing key', 'f_test_keyexists', array($params_without));
$result3 = $benchmark->run('isset() with existing key', 'f_test_isset', array($params_with));
$result4 = $benchmark->run('isset() with non existing key', 'f_test_isset', array($params_without));
$benchmark->compare($result1, $result3);
$benchmark->compare($result2, $result4);
$benchmark->showResults();
Exemplo n.º 9
0
Arquivo: run.php Projeto: ErosZy/CSF
<?php

$config = [];
require_once "./config.php";
require_once "./Benchmark.php";
$bc = new Benchmark($config["test_function"]);
$bc->process_num = $config["process_num"];
$bc->request_num = $config["request_num"];
$bc->server_url = $config["server_url"];
$bc->server_config = parse_url($config["server_url"]);
$send_data = $config["send_data"];
$package_eof = $config["package_eof"];
$bc->process_req_num = intval($bc->request_num / $bc->process_num);
$bc->run();
$bc->report();
function long_tcp(Benchmark $bc)
{
    global $send_data, $package_eof;
    static $client = null;
    static $i;
    static $index;
    $start = microtime(true);
    if (empty($client)) {
        $client = new swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
        $client->set(array('open_eof_check' => true, "package_eof" => $package_eof));
        $end = microtime(true);
        $conn_use = $end - $start;
        $bc->max_conn_time = $conn_use;
        $i = 0;
        $index = 0;
        if (!$client->connect($bc->server_config['host'], $bc->server_config['port'], 2)) {
    if (file_exists($file)) {
        $x = fopen($file, 'r', true);
        fclose($x);
        return true;
    } else {
        return false;
    }
}
function f_test_ofile($file)
{
    $x = @fopen($file, 'r', true);
    if ($x === false) {
        return false;
    } else {
        fclose($x);
        return true;
    }
}
$benchmark = new Benchmark('bench file_exists() Vs fopen()');
$benchmark->setRunningCount(10000);
$params_ok = array(basename(__FILE__));
$params_err = array('this_file_do_not_exists.txt');
$result1 = $benchmark->run('file_exists() with existing file', 'f_test_file_exists', $params_ok);
$result2 = $benchmark->run('file_exists() with non existing file', 'f_test_file_exists', $params_err);
$result3 = $benchmark->run('fopen() with existing file', 'f_test_ofile', $params_ok);
$result4 = $benchmark->run('fopen() with non existing file', 'f_test_ofile', $params_err);
$benchmark->compare($result1, $result2);
$benchmark->compare($result3, $result4);
$benchmark->compare($result1, $result3);
$benchmark->compare($result2, $result4);
$benchmark->showResults();
function f_test_read_object_any(&$x)
{
    $a = $x->name;
    $b = $x->subname;
    $c = $x->id;
    return $a . $b . $c;
}
function f_test_read_array($x)
{
    $a = $x['name'];
    $b = $x['subname'];
    $c = $x['id'];
    return $a . $b . $c;
}
$benchmark = new Benchmark('bench array Vs object');
$benchmark->setRunningCount(10000);
$result1 = $benchmark->run('create object from array', 'f_test_create_object_std');
$result2 = $benchmark->run('instanciate a new object', 'f_test_create_object_spec');
$result3 = $benchmark->run('create array', 'f_test_create_array_declarative');
$result4 = $benchmark->run('fill array', 'f_test_create_array_iterative');
$x = f_test_create_object_std();
$result5 = $benchmark->run('read object created from array', 'f_test_read_object_any', array(&$x));
$x = f_test_create_object_spec();
$result6 = $benchmark->run('read instanciated object', 'f_test_read_object_any', array(&$x));
$x = f_test_create_array_declarative();
$result7 = $benchmark->run('read array', 'f_test_read_array', array(&$x));
$benchmark->compare($result1, $result2);
$benchmark->compare($result3, $result4);
$benchmark->compare($result1, $result3);
$benchmark->compare($result6, $result7);
$benchmark->showResults();
Exemplo n.º 12
0
     * Kills a process properly
     *
     * @param handler &$handle The handler
     * @param array   &$pipes  The pipes
     *
     * @return void
     */
    function killProperly(&$handle, &$pipes)
    {
        // proc_terminate kills the shell process, but won't kill a runaway infinite
        // loop. Get the child processes using ps, before killing the parent.
        $pids = $this->getChildren($handle, $pipes);
        // if we dont close pipes, we can create deadlock, leaving zombie processes.
        foreach ($pipes as &$pipe) {
            fclose($pipe);
        }
        proc_terminate($handle);
        proc_close($handle);
        // Not necessarily available.
        if (function_exists("posix_kill")) {
            foreach ($pids as $pid) {
                if (is_numeric($pid)) {
                    posix_kill($pid, 9);
                }
            }
        }
    }
}
$bench = new Benchmark();
$bench->run();