Skip to content

Commit

Permalink
Added benchmarks for ArrayAccess methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Dec 1, 2021
1 parent ad73a32 commit b7d2066
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
47 changes: 47 additions & 0 deletions modules/Collection/test/Benchmark/ArrayList/ArrayAccessBench.php
@@ -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--);
}
}
Expand Up @@ -11,7 +11,6 @@ class ConstructorBench
{
#[Revs(1000)]
#[Iterations(10)]

public function benchConstruct(): void
{
new ArrayList();
Expand Down

0 comments on commit b7d2066

Please sign in to comment.