[jira] [Commented] (RNG-76) Add a primitive constructor to SplitMix64

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Commented] (RNG-76) Add a primitive constructor to SplitMix64

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/RNG-76?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16913306#comment-16913306 ]

Gilles commented on RNG-76:

Is it necessary to change the other constructor (with a {{Long}} argument)?

For that non performance-critical constructor, I'd rather keep the uniformity of the design (using {{setSeedInternal}}).
And to make it clear why the other constructor is added, that method could be modified to avoid implicit unboxing:
private void setSeedInternal(Long seed) {
    state = seed.longValue();

> Add a primitive constructor to SplitMix64
> -----------------------------------------
>                 Key: RNG-76
>                 URL: https://issues.apache.org/jira/browse/RNG-76
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Trivial
>          Time Spent: 10m
>  Remaining Estimate: 0h
> The constructor for {{SplitMix64}} uses a {{Long}} for the seed. If constructed using a primitive {{long}} then auto-boxing will occur.
> I added a {{long}} version of the constructor to SplitMix64:
> {code:java}
> SplitMix64(Long seed);
> SplitMix64(long seed);
> {code}
> I modified the {{ConstructionPerformance}} benchmark to generate 5000 random seeds as {{Long}} or {{long}} then tested:
> {code:java}
> // Pre-generated Long
> new SplitMix64(Long seed);
> // Pre-generated long that is boxed to Long
> new SplitMix64(Long.valueOf(long seed));
> // Pre-generated long
> new SplitMix64(long seed);
> {code}
> Results:
> ||Method||Score||Error||Median||
> |newSplitMix64Long|34.70|0.85|34.57|
> |newSplitMix64LongValueOf|55.84|5.38|55.91|
> |newSplitMix64long|32.66|1.49|32.46|
> Given that the {{SplitMix64}} is the preferred RNG for seeding from a single {{long}} value it makes sense to add the constructor version that accepts a {{long}}.

This message was sent by Atlassian Jira