[
https://issues.apache.org/jira/browse/RNG-57?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16627234#comment-16627234
]
Alex D Herbert commented on RNG-57:
-----------------------------------
Tried a first attempt at this. It is proving quite a challenge to speed it up.
Here are the results from 5 runs in JMH generating 100000 samples with a
standard RNG or one wrapped with a cache.
I've implemented methods to speed up {{nextBoolean}} for all providers and
{{nextInt}} for {{LongProvider}}.
||Method||randomSourceName||cache||Score||Error||Relative||
|nextBooleanIntProvider|ISAAC|false|5600.46|435.03|1.000|
|nextBooleanIntProvider|ISAAC|true|3084.45|26.1|0.551|
|nextBooleanIntProvider|JDK|false|9734.99|31.55|1.000|
|nextBooleanIntProvider|JDK|true|2947.59|9|0.303|
|nextBooleanIntProvider|KISS|false|4799.21|240.71|1.000|
|nextBooleanIntProvider|KISS|true|3116.05|12.98|0.649|
|nextBooleanIntProvider|MT|false|5658.68|106.18|1.000|
|nextBooleanIntProvider|MT|true|3463.81|1212.98|0.612|
|nextBooleanIntProvider|MWC_256|false|4101.07|1579.94|1.000|
|nextBooleanIntProvider|MWC_256|true|3397.07|1627.95|0.828|
|nextBooleanIntProvider|WELL_1024_A|false|7418.54|3146.43|1.000|
|nextBooleanIntProvider|WELL_1024_A|true|3042.62|41.56|0.410|
|nextBooleanIntProvider|WELL_19937_A|false|8808.53|37.47|1.000|
|nextBooleanIntProvider|WELL_19937_A|true|3405.19|28.51|0.387|
|nextBooleanIntProvider|WELL_19937_C|false|9740.32|112.33|1.000|
|nextBooleanIntProvider|WELL_19937_C|true|2916.81|39.01|0.299|
|nextBooleanIntProvider|WELL_44497_A|false|9469.1|110.86|1.000|
|nextBooleanIntProvider|WELL_44497_A|true|2914.71|52.34|0.308|
|nextBooleanIntProvider|WELL_44497_B|false|9990.53|195.99|1.000|
|nextBooleanIntProvider|WELL_44497_B|true|2933.06|36.3|0.294|
|nextBooleanIntProvider|WELL_512_A|false|6431.45|173.8|1.000|
|nextBooleanIntProvider|WELL_512_A|true|3031.66|25.31|0.471|
|nextBooleanLongProvider|MT_64|false|7090.79|3296.42|1.000|
|nextBooleanLongProvider|MT_64|true|3029.21|19.46|0.427|
|nextBooleanLongProvider|SPLIT_MIX_64|false|3683.5|76.21|1.000|
|nextBooleanLongProvider|SPLIT_MIX_64|true|3086.58|105.96|0.838|
|nextBooleanLongProvider|TWO_CMRES|false|4802.98|76.5|1.000|
|nextBooleanLongProvider|TWO_CMRES|true|3078.19|11.66|0.641|
|nextBooleanLongProvider|XOR_SHIFT_1024_S|false|4618.21|12.35|1.000|
|nextBooleanLongProvider|XOR_SHIFT_1024_S|true|3068.69|1091.08|0.664|
|nextIntLongProvider|MT_64|false|6113.54|10.27|1.000|
|nextIntLongProvider|MT_64|true|4695.68|137.97|0.768|
|nextIntLongProvider|SPLIT_MIX_64|false|3513.22|34.72|1.000|
|nextIntLongProvider|SPLIT_MIX_64|true|3478.33|21.76|0.990|
|nextIntLongProvider|TWO_CMRES|false|4569.36|77.06|1.000|
|nextIntLongProvider|TWO_CMRES|true|4078.62|218.7|0.893|
|nextIntLongProvider|XOR_SHIFT_1024_S|false|4391.85|11.77|1.000|
|nextIntLongProvider|XOR_SHIFT_1024_S|true|3843.81|77.38|0.875|
The slow generators can be improved. The fast ones are more difficult.
> CachedUniformRandomProvider for nextBoolean() and nextInt()
> -----------------------------------------------------------
>
> Key: RNG-57
> URL: https://issues.apache.org/jira/browse/RNG-57
> Project: Commons RNG
> Issue Type: Improvement
> Components: sampling
> Affects Versions: 1.2
> Reporter: Alex D Herbert
> Priority: Minor
> Labels: performance
>
> Implement a wrapper around a {{UniformRandomProvider}} that can cache the
> underlying source of random bytes for use in the methods {{nextBoolean()}}
> and {{nextInt()}} (in the case of {{LongProvider}}). E.g.
> {code:java}
> LongProvider provider = RandomSource.create(RandomSource.SPLIT_MIX_64);
> CachedLongProvider rng = new CachedLongProvider(provider);
> // Uses cached nextLong() 64 times
> rng.nextBoolean();
> // Uses cached nextLong() twice
> rng.nextInt();
> IntProvider provider = RandomSource.create(RandomSource.KISS);
> CachedIntProvider rng2 = new CachedIntProvider(provider);
> // Uses cached nextInt() 32 times
> rng2.nextBoolean();
> // This could be wrapped by a factory method:
> UniformRandomProvider rng = CachedUniformRandomProviderFactory.wrap(
> // Any supported source: IntProvider or LongProvider
> RandomSource.create(RandomSource...));
> {code}
> The implementation should be speed tested to determine the benefit for
> {{nextBoolean()}} and if {{nextInt()}} can be improved for {{LongProviders}}.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)