Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 9b61d47

Browse files
committed
Add memory usage test for #48
1 parent 4525ebc commit 9b61d47

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/Purl/Test/MemoryUsageTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Purl\Test;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Purl\Url;
9+
use function floor;
10+
use function log;
11+
use function memory_get_usage;
12+
use function pow;
13+
use function round;
14+
15+
class MemoryUsageTest extends TestCase
16+
{
17+
public function testMemoryUsage() : void
18+
{
19+
$domains = [
20+
'http://google.de',
21+
'http://google.com',
22+
'http://google.it',
23+
'https://google.de',
24+
'https://google.com',
25+
'https://google.it',
26+
'http://www.google.de',
27+
'http://www.google.com',
28+
'http://www.google.it',
29+
];
30+
31+
$memoryStart = memory_get_usage(true);
32+
33+
foreach ($domains as $key => $domain) {
34+
$purl[$key] = Url::parse($domain);
35+
}
36+
37+
$memoryEnd = memory_get_usage(true);
38+
39+
self::assertEquals($this->roundMemoryUsage($memoryStart), $this->roundMemoryUsage($memoryEnd));
40+
}
41+
42+
private function roundMemoryUsage(float $size) : float
43+
{
44+
return round($size / pow(1024, $i = floor(log($size, 1024))));
45+
}
46+
}

0 commit comments

Comments
 (0)