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

Alex D Herbert commented on RNG-78:
-----------------------------------

Updated the benchmark to add a raw implementation using 
{{ThreadLocal<UniformRandomProvider>}}. This shows how the factory method 
compares with a custom implementation:
||numValues||randomSourceName||Method||Score||Relative||
|0|N/A|threadLocalRandom|2.72|1.00|
|0|N/A|threadLocalRandomWrapped|2.7|0.99|
|0|SPLIT_MIX_64|randomSourceCreate|880.00|196.87|
|0|SPLIT_MIX_64|threadLocalRandomSourceCurrent|6.26|1.40|
|0|SPLIT_MIX_64|threadLocalUniformRandomProvider|4.88|1.79|
|1|N/A|threadLocalRandom|4.47|1.64|
|1|N/A|threadLocalRandomWrapped|4.45|1.64|
|1|SPLIT_MIX_64|randomSourceCreate|780.00|286.76|
|1|SPLIT_MIX_64|threadLocalRandomSourceCurrent|8.83|3.25|
|1|SPLIT_MIX_64|threadLocalUniformRandomProvider|7.88|2.90|
|10|N/A|threadLocalRandom|18.3|1.00|
|10|N/A|threadLocalRandomWrapped|21.4|1.17|
|10|SPLIT_MIX_64|randomSourceCreate|835.00|45.63|
|10|SPLIT_MIX_64|threadLocalRandomSourceCurrent|28.50|1.56|
|10|SPLIT_MIX_64|threadLocalUniformRandomProvider|27.90|1.52|
|100|N/A|threadLocalRandom|154|1.00|
|100|N/A|threadLocalRandomWrapped|196|1.27|
|100|SPLIT_MIX_64|randomSourceCreate|807.00|5.24|
|100|SPLIT_MIX_64|threadLocalRandomSourceCurrent|162.00|1.05|
|100|SPLIT_MIX_64|threadLocalUniformRandomProvider|159.00|1.03|

So using the factory method to get a RNG and generate 1 value is only 
marginally slower than using a custom ThreadLocal<UniformRandomProvider>. This 
shows that the utility class is providing almost optimal performance and avoids 
an end user having to write this boiler plate code for any {{RandomSource}} 
they would like to use.

 

> ThreadLocalRandomSource
> -----------------------
>
>                 Key: RNG-78
>                 URL: https://issues.apache.org/jira/browse/RNG-78
>             Project: Commons RNG
>          Issue Type: New Feature
>          Components: simple
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Minor
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Implement a helper class that can provide thread-local 
> {{UniformRandomProvider}} instances. 
> This can be used as an equivalent of {{ThreadLocalRandom}}:
> {code:java}
> // c.f.
> Random random = ThreadLocalRandom.current();
> // Access a thread-safe random number generator
> UniformRandomProvider rng = 
>     ThreadLocalRandomSource.current(RandomSource.SPLIT_MIX_64);
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to