summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2018-05-31 15:30:32 +0200
committerAnatol Belski <ab@php.net>2018-05-31 15:32:47 +0200
commit35302c22acc2d54354c7146347edcc826ce1effe (patch)
tree4a6853b345d69cf16544aaabf92856628b3c7a17
parentca2e9df56c04facd9b3e993c7c0c657ca45c38b0 (diff)
downloadphp-git-35302c22acc2d54354c7146347edcc826ce1effe.tar.gz
Use hrtime() for timing tests
-rw-r--r--Zend/bench.php12
-rw-r--r--Zend/micro_bench.php12
-rw-r--r--run-tests.php24
3 files changed, 32 insertions, 16 deletions
diff --git a/Zend/bench.php b/Zend/bench.php
index 818ce5fbaf..f76bb3f2bd 100644
--- a/Zend/bench.php
+++ b/Zend/bench.php
@@ -345,22 +345,22 @@ function strcat($n) {
/*****/
-function getmicrotime()
+function gethrtime()
{
- $t = gettimeofday();
- return ($t['sec'] + $t['usec'] / 1000000);
+ $hrtime = hrtime();
+ return (($hrtime[0]*1000000000 + $hrtime[1]) / 1000000000);
}
function start_test()
{
ob_start();
- return getmicrotime();
+ return gethrtime();
}
function end_test($start, $name)
{
global $total;
- $end = getmicrotime();
+ $end = gethrtime();
ob_end_clean();
$total += $end-$start;
$num = number_format($end-$start,3);
@@ -368,7 +368,7 @@ function end_test($start, $name)
echo $name.$pad.$num."\n";
ob_start();
- return getmicrotime();
+ return gethrtime();
}
function total()
diff --git a/Zend/micro_bench.php b/Zend/micro_bench.php
index 70525882eb..c9ea19e263 100644
--- a/Zend/micro_bench.php
+++ b/Zend/micro_bench.php
@@ -238,23 +238,23 @@ function empty_loop($n) {
}
}
-function getmicrotime()
+function gethrtime()
{
- $t = gettimeofday();
- return ($t['sec'] + $t['usec'] / 1000000);
+ $hrtime = hrtime();
+ return (($hrtime[0]*1000000000 + $hrtime[1]) / 1000000000);
}
function start_test()
{
ob_start();
- return getmicrotime();
+ return gethrtime();
}
function end_test($start, $name, $overhead = null)
{
global $total;
global $last_time;
- $end = getmicrotime();
+ $end = gethrtime();
ob_end_clean();
$last_time = $end-$start;
$total += $last_time;
@@ -267,7 +267,7 @@ function end_test($start, $name, $overhead = null)
echo $name.$pad.$num." ".$num2."\n";
}
ob_start();
- return getmicrotime();
+ return gethrtime();
}
function total()
diff --git a/run-tests.php b/run-tests.php
index 59f878dc39..87bd8daa1f 100644
--- a/run-tests.php
+++ b/run-tests.php
@@ -183,6 +183,20 @@ if (getenv('TEST_PHPDBG_EXECUTABLE')) {
$environment['TEST_PHPDBG_EXECUTABLE'] = $phpdbg;
}
+if (!function_exists("hrtime")) {
+ function hrtime(bool $as_num = false)
+ {
+ $t = microtime(true);
+
+ if ($as_num) {
+ return $t*1000000000;
+ }
+
+ $s = floor($t);
+ return array(0 => $s, 1 => ($t - $s)*1000000000);
+ }
+}
+
function verify_config()
{
global $php;
@@ -1923,19 +1937,21 @@ COMMAND $cmd
";
junit_start_timer($shortname);
- $startTime = microtime(true);
+ $hrtime = hrtime();
+ $startTime = $hrtime[0]*1000000000 + $hrtime[1];
$out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null, $captureStdIn, $captureStdOut, $captureStdErr);
junit_finish_timer($shortname);
- $time = microtime(true) - $startTime;
- if ($time * 1000 >= $slow_min_ms) {
+ $hrtime = hrtime();
+ $time = $hrtime[0]*1000000000 + $hrtime[1] - $startTime;
+ if ($time >= $slow_min_ms * 1000000) {
$PHP_FAILED_TESTS['SLOW'][] = array(
'name' => $file,
'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT['via'] : '') . $tested . " [$tested_file]",
'output' => '',
'diff' => '',
- 'info' => $time,
+ 'info' => $time / 1000000000,
);
}