Exemplo n.º 1
0
 private function _test_to_string5digits()
 {
     $digits = 5;
     $bench = new Bench();
     $this->random_usleep();
     $time = $bench->to_string($digits);
     self::assertRegExp(sprintf($this->result_format_regex, $digits), $time);
 }
 public function execute(HTTPRequestCustom $request)
 {
     $this->init();
     $this->test = str_repeat($this->test, 1);
     $bench_non_cached = new Bench();
     $bench_non_cached->start();
     $this->run_non_cached_parsing();
     $bench_non_cached->stop();
     $bench_cached = new Bench();
     $bench_cached->start();
     $this->run_cached_parsing();
     $bench_cached->stop();
     $this->view->put_all(array('RESULT' => StringVars::replace_vars($this->lang['string_template.result'], array('non_cached_time' => $bench_non_cached->to_string(5), 'cached_time' => $bench_cached->to_string(5), 'string_length' => strlen($this->test)))));
     return $this->generate_response();
 }
Exemplo n.º 3
0
function benchLoops(array $tests)
{
    $loops = array('StreamSelectLoop', 'LibEventLoop', 'LibEvLoop');
    foreach ($tests as $testName => $test) {
        foreach ($loops as $loopName) {
            $loopClass = "React\\EventLoop\\{$loopName}";
            $loop = new $loopClass();
            $bench = new Bench();
            $bench->start();
            $test($loop);
            $bench->printSnap("{$loopName}: {$testName}");
        }
        printf("----------------------------------------\n");
    }
}
Exemplo n.º 4
0
 public static function go()
 {
     $results = [];
     for ($i = self::$repeats; $i >= 0; --$i) {
         usleep(0);
         foreach (self::$tests as $label => $data) {
             list($raw, $encoded) = $data;
             $json = json_encode($raw);
             $results[$label]['encode']['json'][] = Bench::doBench('json_encode', [$raw]);
             $results[$label]['encode']['hstore'][] = Bench::doBench('\\Intaro\\HStore\\Coder::encode', [$raw]);
             $results[$label]['decode']['json'][] = Bench::doBench('json_decode', [$json, true]);
             $results[$label]['decode']['hstore'][] = Bench::doBench('\\Intaro\\HStore\\Coder::decode', [$encoded]);
         }
     }
     // print results
     foreach ($results as $label => $ldata) {
         foreach ($ldata as $group => $gdata) {
             echo "=== {$label} ({$group})\n";
             $functions_results = [];
             foreach ($gdata as $function => $r) {
                 $min = min($r);
                 $max = max($r);
                 $avg = array_sum($r) / count($r);
                 $functions_results[$function] = $min;
                 echo sprintf("%8.3fμs min (%8.3fμs avg, %8.3fμs max) - %s\n", $min, $avg, $max, $function);
             }
             $json = $functions_results['json'];
             $hstore = $functions_results['hstore'];
             echo "+++ ";
             if ($json > $hstore) {
                 echo sprintf("hstore %.2f%% faster that json", 100 * $json / $hstore);
             } else {
                 echo sprintf("json %.2f%% faster that hstore", 100 * $hstore / $json);
             }
             echo "\n";
         }
     }
 }
Exemplo n.º 5
0
<?php

// Description: Serialize scalar int
require_once 'bench.php';
$b = new Bench('serialize-scalar-int');
$var = 1;
for ($i = 0; $i < 40; $i++) {
    $b->start();
    for ($j = 0; $j < 3500000; $j++) {
        $ser = igbinary_serialize($var);
    }
    $b->stop($j);
    $b->write();
}
Exemplo n.º 6
0
 private function get_delta_duration()
 {
     return Bench::get_microtime() - $this->start;
 }
Exemplo n.º 7
0
require_once $_SERVER["DOCUMENT_ROOT"] . "/scriptacid/core/application.php";
SetTitle('Проект "ScriptACID CMF"');
App::page(function (&$arPageParams) {
    ?>

<?php 
    App::USER()->Authorize('1');
    ?>

<?php 
    Bench::startTime(":catalog.section");
    App::callComponent(":catalog.section", "", array("TYPE" => "orion_locations", "CATALOG_ID" => "3", "CACHE_OFF" => "Y", "COMPONENT_AJAX_MODE" => "N"));
    ?>
<p>Время: <?php 
    echo Bench::stopTime(":catalog.section");
    ?>
</p>


<?php 
    Bench::startTime(":catalog.element.add@_default");
    App::callComponent(":catalog.element.add", "_default", array("COMPONENT_AJAX_MODE" => "N", "FIELDS" => array("ID", "ACTIVE", "NAME", "CATALOG_SECTION_ID", "CATALOG_ID", "SORT", "CODE", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "TAGS"), "TYPE" => "orion_locations", "CATALOG_ID" => "3", "ID" => '{%_GET[ID]}', "ACTION" => '{%_GET[ACTION]}', "LIST_URL" => "/test/test_ajax_component_call.php", "ELEMENT_URL" => "/test/test_ajax_component_call.php?ID=#ID#"));
    ?>
<p>Время: <?php 
    echo Bench::stopTime(":catalog.element.add@_default");
    ?>
</p>

<?php 
});
// end makePage
Exemplo n.º 8
0
<?php

namespace ScriptAcid;

require_once $_SERVER['DOCUMENT_ROOT'] . '/scriptacid/core/application.php';
App::page(function () {
    // Не знаю в чем прикол, но надо обязательно вызвать первый раз, что бы тесты не искажались.
    startBench('_this_need_for_correct_bench_at_first_call');
    stopBench('_this_need_for_correct_bench_at_first_call');
    Bench::startTime('_this_need_for_correct_bench_at_first_call');
    Bench::stopTime('_this_need_for_correct_bench_at_first_call');
    define('IF_DEFINE', true);
    define('FORCE_DEFINE', true);
    Bench::startTime('IF_DEFINE');
    if (!defined('IF_DEFINE')) {
        define('IF_DEFINE', true);
    }
    d(Bench::stopTime('IF_DEFINE'));
    Bench::startTime('FORCE_DEFINE');
    @define('FORCE_DEFINE', true);
    d(Bench::stopTime('FORCE_DEFINE'));
    ?>
	
<?php 
});
// end of makePage
Exemplo n.º 9
0
 /**
  * Reset timer.
  *
  * @return void;
  */
 public static function reset()
 {
     self::$marks = array();
     self::$start = null;
     self::$stop = null;
 }
Exemplo n.º 10
0
<?php

error_reporting(E_ERROR | E_WARNING);
setlocale(LC_TIME, 'ru_RU.UTF-8');
// autoloader :-)
include_once 'cloader.php';
$results = array();
$am = new TestClass();
// for total time
$c = new Bench();
// 10 iterations for averages
for ($a = 1; $a <= 10; $a++) {
    // for one run bench
    $b = new Bench();
    for ($i = 1; $i <= 100000; $i++) {
        $nav = $am->generateMenu();
    }
    $results[] = $b->end(false);
}
echo '<pre>' . print_r($results, 1) . '</pre>';
$total = $c->end(false);
echo 'Total: ' . $total . ', Average: ' . $total / count($results);
Exemplo n.º 11
0
 function stop()
 {
     $this->duration = Bench::get_microtime() - $this->start;
 }
Exemplo n.º 12
0
 /**
  * Inits the bench
  */
 public static function init_bench()
 {
     self::$bench = new Bench();
     self::$bench->start();
 }
Exemplo n.º 13
0
function bench_string($string_size, $string_iteration)
{
    echo '<h1>String</h1>';
    $string = '';
    for ($i = 0; $i < $string_size; $i++) {
        $string .= '.';
    }
    $bench = new Bench();
    $bench->start();
    for ($i = 0; $i < $string_iteration; $i++) {
        string_by_ref($string);
    }
    $bench->stop();
    echo 'Ref: ' . $bench->to_string() . '<hr />';
    $bench = new Bench();
    $bench->start();
    for ($i = 0; $i < $string_iteration; $i++) {
        string_by_cp($string);
    }
    $bench->stop();
    echo 'Copy: ' . $bench->to_string() . '<hr />';
}