pholser/junit-quickcheck

Optimize SourceOfRandomness#choose(java.util.Collection<T>)

vlsi opened this issue · 4 comments

vlsi commented

Currently SourceOfRandomness#choose(java.util.Collection) converts the collection to array, however

  1. If collection size is 1, then there's no need to generate a random number
  2. If collection is a List + java.util.RandomAccess, then .get(index) would be faster than collecting the values to array.

choose(T[] items) could be optimized as well for the case of single item (avoid generating random when outcome is known to be 0)

@visi Sounds reasonable. Would you be willing to make this change and submit a PR?

@vlsi This should now be on both 0.9-branch and master.

vlsi commented

I do not get it. Do you suggest me to create two PRs?

@vlsi Sorry for the confusion. I meant to say that I've made the changes suggested in this issue in a separate PR. Those changes are now available on both of the branches I mentioned. Let me know how this looks, if you have a moment. Thanks!