Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added benchmarks for ArrayAccess methods
- Loading branch information
1 parent
ad73a32
commit b7d2066
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
modules/Collection/test/Benchmark/ArrayList/ArrayAccessBench.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Elephox\Collection\Benchmark\ArrayList; | ||
|
||
use Elephox\Collection\ArrayList; | ||
use PhpBench\Attributes\BeforeMethods; | ||
use PhpBench\Attributes\Revs; | ||
|
||
#[BeforeMethods('setUp')] | ||
class ArrayAccessBench | ||
{ | ||
private ArrayList $arrayList; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->arrayList = new ArrayList(range(1, 1000)); | ||
} | ||
|
||
#[Revs(100)] | ||
public function benchOffsetExists(): void | ||
{ | ||
$this->arrayList->offsetExists(50); | ||
} | ||
|
||
#[Revs(100)] | ||
public function benchOffsetGet(): void | ||
{ | ||
$this->arrayList->offsetGet(10); | ||
} | ||
|
||
#[Revs(100)] | ||
public function benchOffsetSet(): void | ||
{ | ||
$this->arrayList->offsetSet(0, 1); | ||
} | ||
|
||
#[Revs(100)] | ||
public function benchOffsetUnset(): void | ||
{ | ||
static $i; | ||
|
||
$i ??= 1000; | ||
|
||
$this->arrayList->offsetUnset($i--); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters