Skip to content

Add 'instance UniformRange Natural'#126

Merged
curiousleo merged 1 commit intoidontgetoutmuch:interface-to-performancefrom
curiousleo:uniformrange-natural
May 11, 2020
Merged

Add 'instance UniformRange Natural'#126
curiousleo merged 1 commit intoidontgetoutmuch:interface-to-performancefrom
curiousleo:uniformrange-natural

Conversation

@curiousleo
Copy link
Copy Markdown
Collaborator

The main addition here is to add instance UniformRange Natural, also see haskell#44.

To do this, I changed the Integer-specific uniformIntegerM to a generic uniformIntegralM. Since this function was and is recursive, I changed the pragma from INLINE to INLINEABLE.

I made sure that these more generic functions are no slower than before. Note that random/Integer benchmarks small ranges, for which a fast path is triggered; uniformR/unbounded/Integer and the new uniformR/unbounded/Natural benchmark very large ranges where there is no fast path.

Before (9ee79a7):

pure/random/Integer                      mean 362.6 μs  ( +- 44.38 μs  )
pure/uniformR/unbounded/Integer          mean 189.3 ms  ( +- 8.531 ms  )

After (this PR):

pure/random/Integer                      mean 369.0 μs  ( +- 36.89 μs  )
pure/uniformR/unbounded/Integer          mean 122.8 ms  ( +- 6.044 ms  )
pure/uniformR/unbounded/Natural          mean 110.6 ms  ( +- 16.08 ms  )

Other changes:

  • specs use uniformR instead of randomR; this allow us to make the constraints more precise
  • added Natural benchmark and specs
  • sorted some imports alphabetically

@curiousleo curiousleo force-pushed the uniformrange-natural branch from dba6aa8 to bda3a67 Compare May 11, 2020 14:59
Copy link
Copy Markdown
Owner

@idontgetoutmuch idontgetoutmuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Copy Markdown
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@curiousleo curiousleo merged commit 1b07f29 into idontgetoutmuch:interface-to-performance May 11, 2020
@curiousleo curiousleo deleted the uniformrange-natural branch May 11, 2020 16:25
curiousleo added a commit that referenced this pull request May 13, 2020
curiousleo added a commit that referenced this pull request May 13, 2020
lehins pushed a commit that referenced this pull request May 18, 2020
curiousleo added a commit that referenced this pull request May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants