testing promises with php

This commit is contained in:
2019-11-22 20:34:10 +01:00
commit 3a4b04c1ec
5 changed files with 93 additions and 0 deletions

24
promises/lib.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace Lib;
function microtime_calc(): array
{
static $last = null; // 1st time
static $sum = 0.0; // 1st time
$mt = microtime(true);
$diff = is_null($last)? 0.0: bcsub($mt, $last);
$sum = bcadd($sum, $diff);
$last = $mt;
return [$sum, $diff];
}
function printf(string $str, ...$args): int
{
return \printf("∑%.6f +%.6f | ". $str."\n", ...microtime_calc(), ...$args);
}
function plain(): void
{
header('Content-Type: text/plain');
}