Skip to content

Commit f40f457

Browse files
committed
Added Vercel livedemo
1 parent ab429ce commit f40f457

File tree

7 files changed

+38
-24
lines changed

7 files changed

+38
-24
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ vendor/
22
.git/
33
.github/
44
.notes
5-
composer.lock
5+
composer.lock
6+
.vercel

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This Package uses `$_SERVER['REQUEST_TIME_FLOAT']` and `microtime()` to calculate the difference that has passed between both times, when instantiated. It also provides a basic implementation of `hrtime()`, which allows measuring processing times with higher precision.
44

5-
See [./examples/mycrobench](./examples/mycrobench/index.php) for examples.
5+
See [./public/index.php](./public/index.php) for examples or check the livedemo on [Vercel](https://mycro-bench.vercel.app/).
66

77
```terminal
88
composer require eypsilon/MycroBench
@@ -70,6 +70,7 @@ MycroBench::getBench(true)
7070
Get `microtimes` with the system's high resolution time using [hrtime()](https://www.php.net/manual/de/function.hrtime.php).
7171

7272
Microsec: `00.019045`
73+
7374
High Reso: `0.019044332`
7475

7576
```php

api/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
require dirname(__DIR__) . '/public/index.php';
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@
33
use Many\MycroBench;
44

55
/**
6-
* To use this example, copy the './examples/mycrobench'
7-
* directory to where composers './vendor' directory is
8-
*
96
* For demo purposes only
10-
*
11-
* $ ~/terminal/in/./examples/mycrobench
12-
* php -S localhost:8000
13-
* http://localhost:8000
147
*/
158

16-
require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';
9+
require_once dirname(__DIR__) . '/vendor/autoload.php';
1710

1811
/**
1912
* @param int $xTimes
@@ -22,7 +15,7 @@
2215
function do_rand_stuff(int $xTimes)
2316
{
2417
do {
25-
range(0, $do[] = rand(1e1, 5e5));
18+
range(0, $do[] = rand(1e3, 5e5));
2619
} while (--$xTimes);
2720

2821
return sprintf('ranged: %s', implode(', ',
@@ -32,11 +25,10 @@ function do_rand_stuff(int $xTimes)
3225
));
3326
}
3427

35-
3628
/**
3729
* @var int Run Benchmarks x times
3830
*/
39-
$doBenchys = 5;
31+
$doBenchys = 25;
4032

4133
/**
4234
* Run Benchmarks
@@ -50,28 +42,34 @@ function do_rand_stuff(int $xTimes)
5042

5143
foreach(range(1, $doBenchys) as $i)
5244
{
53-
$runBenchys['task_list'][$i] = do_rand_stuff(rand(5, 10));
45+
$i = str_pad($i, strlen((string) $doBenchys), '0', STR_PAD_LEFT);
5446

55-
try {
47+
$runBenchys['task_list'][$i] = do_rand_stuff(rand(4, 9));
5648

49+
try {
5750
// get micro bench with internally staid start times
5851
// set first param to true to get high resolution times
5952
$runBenchys['benchmarks'][$i] = MycroBench::getBench(true);
6053

54+
// Get high resolution time only. The benches below will seem
55+
// "faster", that's because their start time is just 5 lines ago.
56+
// Since nothing happened in between, it takes practically no time.
57+
$runBenchys['hr_bench'][$i] = MycroBench::hrBench();
6158
} catch(Exception $e) {
6259
$runBenchys['exception'][$i] = $e->getMessage();
6360
}
6461
}
6562
}
6663

67-
6864
/**
69-
* Template Engin © 1992 eypsilon
65+
* @Template\Engin © 1992 eypsilon
7066
*/
7167
?><!DOCTYPE html>
72-
<html><head><meta charset="utf-8" />
68+
<html>
69+
<head>
70+
<meta charset="utf-8">
7371
<title><?= $cName = MycroBench::class ?> | local-dev-many-title</title>
74-
<meta name="description" content="<?= $cName ?> Example Page" />
72+
<meta name="description" content="<?= $cName ?> Example Page">
7573
<style>header, footer {text-align: center}</style>
7674
</head>
7775
<body>
@@ -84,14 +82,15 @@ function do_rand_stuff(int $xTimes)
8482
print_r($runBenchys ?? null);
8583

8684
try {
87-
print_r(MycroBench::get(false, realpath('../../..')));
85+
print_r(MycroBench::get(false, realpath('./../..')));
8886
} catch(Exception $e) {
89-
print '<h2>' . $e->getMessage() . '</h2>';
87+
print '<hr /><h2>' . $e->getMessage() . '</h2>';
9088
}
9189
?></pre>
9290
</main>
9391
<hr />
9492
<footer>
95-
<p>© <?= $cName ?></p>
93+
<p>© <?= date('Y') ?> <?= $cName ?></p>
9694
</footer>
97-
</body></html>
95+
</body>
96+
</html>

src/MycroBench.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function getDateDiff($d1, $d2, string $f=null): string
279279
* @param int number format decimal, numbers after comma
280280
* @param int unit file size index
281281
* @param array unit file sizes
282-
* @return string|int
282+
* @return string|int ["4 MB" | 0]
283283
*/
284284
public static function readableBytes(int $b, int $n=2, int $i=0, array $u=['B', 'KB', 'MB', 'GB', 'TB', 'PB'])
285285
{

vercel.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"functions": {
3+
"api/index.php": {
4+
"runtime": "vercel-php@0.5.2"
5+
}
6+
},
7+
"routes": [
8+
{ "src": "/(.*)", "dest": "/api/index.php" }
9+
]
10+
}

0 commit comments

Comments
 (0)