/** * Creates a new test case in the suite. * * @param object $function Test function * @param string $name Test name * * @return object SIG_Test */ function test($function, $name = null) { xp_signal($this->_test, xp_exhaust(1, function ($signal) use($name, $function) { $signal->name = $name; return $function($signal); })); }
<?php xp_import('time'); $precision = 10; $signal = new \time\SIG_Awake($precision, TIME_MILLISECONDS); $signal->time = milliseconds(); $precision_timing = []; $function = xp_exhaust(100, function ($signal) use($precision, &$precision_timing) { $timing = intval(floatval(milliseconds() - $signal->time)) - $precision; echo $timing . PHP_EOL; // if ($timing > 100000) { // // Second change // $timing = 0; // } $precision_timing[] = [$timing, 0]; $signal->time = milliseconds(); }); xp_signal($signal, $function); xp_on_shutdown(function () use(&$precision_timing) { array_shift($precision_timing); $results = ['msPrecision' => $precision_timing]; ob_start(); include dirname(realpath(__FILE__)) . '/chart.php'; $data = ob_get_contents(); ob_end_clean(); file_put_contents('millisecond_precision.html', $data); echo "Performance chart in millisecond_precision.html" . PHP_EOL; });
<?php /** * Copyright 2010-12 Nickolas Whiting. All rights reserved. * Use of this source code is governed by the Apache 2 license * that can be found in the LICENSE file. */ require_once dirname(realpath(__FILE__)) . '/../__init__.php'; xp_import('unittest'); unittest\test(function ($test) { $process = xp_exhaust(10, null); $test->equal(10, $process->exhaustion()); }, 'API Exhaust');
<?php xp_import('time'); $precision = 1; $signal = new \time\SIG_Awake($precision, TIME_SECONDS); $signal->time = time(); $precision_timing = []; $function = xp_exhaust(10, function ($signal) use($precision, &$precision_timing) { $timing = intval(floatval(time() - $signal->time)) - $precision; if ($timing > 100000 || $timing < 0) { // Second change $timing = 0; } $precision_timing[] = [$timing, 0]; $signal->time = time(); }); xp_signal($signal, $function); xp_on_shutdown(function () use(&$precision_timing) { array_shift($precision_timing); $results = ['msPrecision' => $precision_timing]; ob_start(); include dirname(realpath(__FILE__)) . '/chart.php'; $data = ob_get_contents(); ob_end_clean(); file_put_contents('second_precision.html', $data); echo "Performance chart in second_precision.html" . PHP_EOL; });
<?php xp_import('network'); $ops = 0; $thread = xp_threaded_process(function () { $start_time = 0; $this->operations = 0; $sig = XP_SIG('a'); do { echo $ops; xp_emit($sig); $this->operations++; $ops = $this->operations / (microtime(true) - $start_time); } while (true); }); $ops_sig = xp_signal(XP_SIG('op'), xp_exhaust(null, $thread)); xp_emit(XP_SIG('op')); // $server = network\connect('0.0.0.0', ['port'=>8000]); // $server->on_connect(xp_null_exhaust(function($server) use ($ops){ // $server->socket->write($ops); // $server->socket->disconnect(); // })); // $server = // $iterations = 1000000; // $start = microtime(true); // for ($i=0;$i<$iterations;$i++) {} // $end = microtime(true); // $loop_time = $end - $start; // $sig = XP_SIG(null); // $start = microtime(true); // for ($i=0;$i<$iterations;$i++) {
<?php print microseconds(); xp_import('time'); $precision = 500; $signal = new \time\SIG_Awake($precision, TIME_MICROSECONDS); $precision_timing = []; xp_signal($signal, xp_exhaust(5500, function ($signal) use($precision, &$precision_timing) { if (!isset($signal->time)) { $signal->time = microseconds(); return true; } $timing = floatval((microseconds() - $signal->time) * 1000000) - $precision; if ($timing > 1000 || $timing < 0) { // Second change $signal->time = microseconds(); return; } $precision_timing[] = [$timing, 0]; $signal->time = microseconds(); })); xp_on_shutdown(function () use(&$precision_timing) { array_shift($precision_timing); $results = ['usPrecision' => $precision_timing]; ob_start(); include dirname(realpath(__FILE__)) . '/chart.php'; $data = ob_get_contents(); ob_end_clean(); file_put_contents('microsecond_precision.html', $data); echo "Performance chart in precision.html" . PHP_EOL; });