Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Improve unique generator performance #491

Merged
merged 1 commit into from
Jan 4, 2015

Conversation

ikwattro
Copy link
Contributor

@ikwattro ikwattro commented Jan 4, 2015

Hi,

Currently the unique generator keeps the already used elements as array values and performs the lookup with in_array to assert that the generated value has not already been used. This operation is a O(n) operation which becomes slower in time for large datasets generation.

I refactored this operation to uses array indexes instead, which will leads to hash table lookups that are O(1) operations.

I did a little benchmark generating 10k unixTimes, the generation time is decreased from 1.77 seconds to 0.37 seconds.

@GrahamCampbell
Copy link
Contributor

Cool. :)

fzaninotto added a commit that referenced this pull request Jan 4, 2015
Improve unique generator performance
@fzaninotto fzaninotto merged commit b0795fe into fzaninotto:master Jan 4, 2015
@fzaninotto
Copy link
Owner

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants