Skip to content

[RFC] Speed up the test_it_generates_unique_ids() by using assertSame() instead of assertNotContains() #1

@viccherubini

Description

@viccherubini

Neat project! I love the simplicity and speed. I did some benchmarking and the test_it_generates_unique_ids() test uses assertNotContains() in a loop of 1000 iterations. On my machine, this test takes about 165312875 nanoseconds to run. When replacing the assertNotContains() call to a single assertSame() call at the end of the loop, the test drops to about 869500 nanoseconds, an improvement of 3 orders of magnitude.

public function test_it_generates_unique_ids()
{
    $ids = [];

    for ($i = 0; $i < 1000; $i++) {
        $ids[] = ObjectId::generate();
    }

    $this->assertSame($ids, array_unique($ids));
}

Would you like me to open a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions