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

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

I have compiled a new listing using the output of {{ConstructionPerformance}} 
and {{GenerationPerformance}}.

For reference the construction benchmark creates 500 RNGs, using pre-built 
seeds where appropriate. Test the following construction methods:
 * Create using the native constructor with the *new* keyword
 * Create using a cached *{{Constructor<Object>}}* with *{{newInstance}}*
 * Create using a cached *{{Class<?>}}*, lookup the *{{Constructor<Object>}}* 
and use *{{newInstance}}*
 * Create using *{{RandomSource}}* with the *native* seed
 * Create using *{{RandomSource}}* with a *{{null}}* seed
 * Create using *{{RandomSource}}* with a *{{Long}}* seed
 * Create using *{{RandomSource}}* with a *truncated native* seed forcing self 
seeding
 * Create using *{{RandomSource}}* with a *{{byte[]}}* of the appropriate length

The time for construction of a single generator is the benchmark time divided 
by 500.

Generation time is shown for the given number of values. For simplicity this is 
created by linearly scaling the generation time for 1,000,000 values. The time 
uses the native method of the generator (either {{nextInt}} or {{nextLong}}) so 
*is not comparable between generators of different types*. It is indicative of 
the speed it will take to create a generator and output values.

The table is constructed by adding the time for construction to the generation 
time. Only the total time is shown for the construction using *new*. All other 
times are relative to this. The table is sorted by speed of the *new* 
construction and grouped by the number of values generated.

*Note: This listing involves adding of times from two benchmarks run on the 
same computer, using the same JMH benchmark settings for average time in 
microseconds. An independent test using construction and generation together 
indicated this is a valid approach as the numbers for creating 1,000,000 values 
were within 10%.*
||Values||Generation||RandomSource||new||newInstance||lookupNewInstance||createNativeSeed||createNullSeed||createLongSeed||createSelfSeed||createByteArray||
|0|0|SPLIT_MIX_64|0.0091|1.89|5.63|8.62|13.48|9.11|0|12.11|
|0|0|KISS|0.02132|1.37|2.82|4.07|67.38|10.79|4.53|6.33|
|0|0|WELL_512_A|0.02536|1.36|2.59|4.14|64.37|14.00|4.88|10.26|
|0|0|WELL_1024_A|0.03462|1.36|2.37|3.39|45.20|8.31|5.66|13.54|
|0|0|JDK|0.03498|0.79|1.93|2.34|4.54|2.82|0|3.68|
|0|0|XOR_SHIFT_1024_S|0.03962|1.28|2.10|2.60|75.25|12.26|3.55|7.24|
|0|0|MWC_256|0.46924|0.97|1.28|1.18|4.50|2.09|2.37|6.70|
|0|0|WELL_19937_C|0.49446|1.10|0.99|1.20|4.58|2.29|4.51|14.01|
|0|0|WELL_19937_A|0.53464|0.91|1.17|1.11|4.89|2.13|4.65|12.97|
|0|0|WELL_44497_B|1.10144|1.16|1.03|0.97|2.93|2.41|4.50|16.66|
|0|0|WELL_44497_A|1.189|0.98|0.89|1.06|3.06|1.87|5.32|12.29|
|0|0|ISAAC|2.46102|0.97|0.91|0.86|1.44|1.03|1.19|2.29|
|0|0|MT_64|7.13676|1.05|0.95|1.00|0.79|0.54|0.46|0.98|
|0|0|MT|11.00264|1.00|1.00|1.06|0.80|0.68|0.62|1.38|
|0|0|TWO_CMRES|133.73698|1.01|0.95|1.12|1.10|1.09|0|1.08|
|1|0.00398456|SPLIT_MIX_64|0.01308456|1.62|4.22|6.30|9.68|6.64|0|8.73|
|1|0.00603231|KISS|0.02735231|1.29|2.41|3.40|52.74|8.63|3.75|5.16|
|1|0.00735691|WELL_512_A|0.03271691|1.28|2.23|3.43|50.12|11.08|4.01|8.18|
|1|0.00744491|WELL_1024_A|0.04206491|1.30|2.13|2.97|37.38|7.02|4.84|11.32|
|1|0.01915509|JDK|0.05413509|0.87|1.60|1.86|3.29|2.18|0|2.73|
|1|0.00488982|XOR_SHIFT_1024_S|0.04450982|1.25|1.98|2.43|67.09|11.02|3.27|6.56|
|1|0.00413311|MWC_256|0.47337311|0.97|1.28|1.18|4.47|2.08|2.36|6.65|
|1|0.010572|WELL_19937_C|0.505032|1.09|0.99|1.20|4.51|2.26|4.44|13.74|
|1|0.01000549|WELL_19937_A|0.54464549|0.92|1.16|1.11|4.81|2.10|4.59|12.75|
|1|0.01212127|WELL_44497_B|1.11356127|1.16|1.03|0.97|2.91|2.40|4.46|16.49|
|1|0.01106587|WELL_44497_A|1.20006587|0.98|0.90|1.06|3.04|1.86|5.28|12.19|
|1|0.00597662|ISAAC|2.46699662|0.97|0.91|0.86|1.44|1.03|1.19|2.28|
|1|0.00619041|MT_64|7.14295041|1.05|0.95|1.00|0.79|0.54|0.46|0.98|
|1|0.00663587|MT|11.00927587|1.00|1.00|1.06|0.80|0.68|0.62|1.38|
|1|0.00458057|TWO_CMRES|133.74156057|1.01|0.95|1.12|1.10|1.09|0|1.08|
|10|0.0398456|SPLIT_MIX_64|0.0489456|1.16|1.86|2.42|3.32|2.51|0|3.07|
|10|0.0603231|KISS|0.0816431|1.10|1.47|1.80|18.34|3.56|1.92|2.39|
|10|0.0735691|WELL_512_A|0.0989291|1.09|1.41|1.81|17.24|4.33|1.99|3.37|
|10|0.0744491|WELL_1024_A|0.1090691|1.11|1.44|1.76|15.03|3.32|2.48|4.98|
|10|0.1915509|JDK|0.2265309|0.97|1.14|1.21|1.55|1.28|0|1.41|
|10|0.0488982|XOR_SHIFT_1024_S|0.0885182|1.13|1.49|1.72|34.23|6.04|2.14|3.79|
|10|0.0413311|MWC_256|0.5105711|0.98|1.26|1.17|4.22|2.00|2.26|6.24|
|10|0.10572|WELL_19937_C|0.60018|1.08|0.99|1.17|3.95|2.06|3.89|11.72|
|10|0.1000549|WELL_19937_A|0.6346949|0.93|1.14|1.10|4.27|1.95|4.08|11.08|
|10|0.1212127|WELL_44497_B|1.2226527|1.15|1.02|0.97|2.74|2.27|4.15|15.11|
|10|0.1106587|WELL_44497_A|1.2996587|0.98|0.90|1.05|2.89|1.79|4.95|11.33|
|10|0.0597662|ISAAC|2.5207862|0.97|0.91|0.86|1.43|1.03|1.19|2.26|
|10|0.0619041|MT_64|7.1986641|1.05|0.95|1.00|0.79|0.54|0.46|0.98|
|10|0.0663587|MT|11.0689987|1.00|1.00|1.06|0.80|0.68|0.62|1.38|
|10|0.0458057|TWO_CMRES|133.7827857|1.01|0.95|1.12|1.10|1.09|0|1.08|
|100|0.398456|SPLIT_MIX_64|0.407556|1.02|1.10|1.17|1.28|1.18|0|1.25|
|100|0.603231|KISS|0.624551|1.01|1.06|1.10|3.27|1.33|1.12|1.18|
|100|0.735691|WELL_512_A|0.761051|1.01|1.05|1.10|3.11|1.43|1.13|1.31|
|100|0.744491|WELL_1024_A|0.779111|1.02|1.06|1.11|2.96|1.33|1.21|1.56|
|100|1.915509|JDK|1.950489|1.00|1.02|1.02|1.06|1.03|0|1.05|
|100|0.488982|XOR_SHIFT_1024_S|0.528602|1.02|1.08|1.12|6.57|1.84|1.19|1.47|
|100|0.413311|MWC_256|0.882551|0.99|1.15|1.10|2.86|1.58|1.73|4.03|
|100|1.0572|WELL_19937_C|1.55166|1.03|1.00|1.06|2.14|1.41|2.12|5.15|
|100|1.000549|WELL_19937_A|1.535189|0.97|1.06|1.04|2.35|1.39|2.27|5.17|
|100|1.212127|WELL_44497_B|2.313567|1.08|1.01|0.99|1.92|1.67|2.66|8.45|
|100|1.106587|WELL_44497_A|2.295587|0.99|0.95|1.03|2.07|1.45|3.24|6.85|
|100|0.597662|ISAAC|3.058682|0.98|0.93|0.89|1.36|1.02|1.16|2.04|
|100|0.619041|MT_64|7.755801|1.04|0.96|1.00|0.80|0.58|0.50|0.98|
|100|0.663587|MT|11.666227|1.00|1.00|1.06|0.81|0.70|0.64|1.36|
|100|0.458057|TWO_CMRES|134.195037|1.01|0.95|1.12|1.10|1.09|0|1.08|
|10000|39.8456|SPLIT_MIX_64|39.8547|1.00|1.00|1.00|1.00|1.00|0|1.00|
|10000|60.3231|KISS|60.34442|1.00|1.00|1.00|1.02|1.00|1.00|1.00|
|10000|73.5691|WELL_512_A|73.59446|1.00|1.00|1.00|1.02|1.00|1.00|1.00|
|10000|74.4491|WELL_1024_A|74.48372|1.00|1.00|1.00|1.02|1.00|1.00|1.01|
|10000|191.5509|JDK|191.58588|1.00|1.00|1.00|1.00|1.00|0|1.00|
|10000|48.8982|XOR_SHIFT_1024_S|48.93782|1.00|1.00|1.00|1.06|1.01|1.00|1.01|
|10000|41.3311|MWC_256|41.80034|1.00|1.00|1.00|1.04|1.01|1.02|1.06|
|10000|105.72|WELL_19937_C|106.21446|1.00|1.00|1.00|1.02|1.01|1.02|1.06|
|10000|100.0549|WELL_19937_A|100.58954|1.00|1.00|1.00|1.02|1.01|1.02|1.06|
|10000|121.2127|WELL_44497_B|122.31414|1.00|1.00|1.00|1.02|1.01|1.03|1.14|
|10000|110.6587|WELL_44497_A|111.8477|1.00|1.00|1.00|1.02|1.01|1.05|1.12|
|10000|59.7662|ISAAC|62.22722|1.00|1.00|0.99|1.02|1.00|1.01|1.05|
|10000|61.9041|MT_64|69.04086|1.00|1.00|1.00|0.98|0.95|0.94|1.00|
|10000|66.3587|MT|77.36134|1.00|1.00|1.01|0.97|0.95|0.95|1.05|
|10000|45.8057|TWO_CMRES|179.54268|1.00|0.96|1.09|1.08|1.07|0|1.06|
|100000|398.456|SPLIT_MIX_64|398.4651|1.00|1.00|1.00|1.00|1.00|0|1.00|
|100000|603.231|KISS|603.25232|1.00|1.00|1.00|1.00|1.00|1.00|1.00|
|100000|735.691|WELL_512_A|735.71636|1.00|1.00|1.00|1.00|1.00|1.00|1.00|
|100000|744.491|WELL_1024_A|744.52562|1.00|1.00|1.00|1.00|1.00|1.00|1.00|
|100000|1915.509|JDK|1915.54398|1.00|1.00|1.00|1.00|1.00|0|1.00|
|100000|488.982|XOR_SHIFT_1024_S|489.02162|1.00|1.00|1.00|1.01|1.00|1.00|1.00|
|100000|413.311|MWC_256|413.78024|1.00|1.00|1.00|1.00|1.00|1.00|1.01|
|100000|1057.2|WELL_19937_C|1057.69446|1.00|1.00|1.00|1.00|1.00|1.00|1.01|
|100000|1000.549|WELL_19937_A|1001.08364|1.00|1.00|1.00|1.00|1.00|1.00|1.01|
|100000|1212.127|WELL_44497_B|1213.22844|1.00|1.00|1.00|1.00|1.00|1.00|1.01|
|100000|1106.587|WELL_44497_A|1107.776|1.00|1.00|1.00|1.00|1.00|1.00|1.01|
|100000|597.662|ISAAC|600.12302|1.00|1.00|1.00|1.00|1.00|1.00|1.01|
|100000|619.041|MT_64|626.17776|1.00|1.00|1.00|1.00|0.99|0.99|1.00|
|100000|663.587|MT|674.58964|1.00|1.00|1.00|1.00|0.99|0.99|1.01|
|100000|458.057|TWO_CMRES|591.79398|1.00|0.99|1.03|1.02|1.02|0|1.02|

The effect of construction and generation can be more easily observed using a 
table of the relative contribution of the generation time to the total time. 
Here the total time is made using construction with the *new* keyword or via 
the default *{{RandomSource.create}}* method with a *native* seed or *null* 
seed. Note: Times for the *create* method are relative to *new* (as above) but 
the generating % is computed using the total time.
||Values||Generation||RandomSource||new + Generation||Generating 
(%)||createNativeSeed (relative)||Generating (%)||createNullSeed 
(relative)||Generating (%)||
|0|0|SPLIT_MIX_64|0.0091|0.00|8.62|0.00|13.48|0.00|
|0|0|KISS|0.02132|0.00|4.07|0.00|67.38|0.00|
|0|0|WELL_512_A|0.02536|0.00|4.14|0.00|64.37|0.00|
|0|0|WELL_1024_A|0.03462|0.00|3.39|0.00|45.2|0.00|
|0|0|JDK|0.03498|0.00|2.34|0.00|4.54|0.00|
|0|0|XOR_SHIFT_1024_S|0.03962|0.00|2.6|0.00|75.25|0.00|
|0|0|MWC_256|0.46924|0.00|1.18|0.00|4.5|0.00|
|0|0|WELL_19937_C|0.49446|0.00|1.2|0.00|4.58|0.00|
|0|0|WELL_19937_A|0.53464|0.00|1.11|0.00|4.89|0.00|
|0|0|WELL_44497_B|1.10144|0.00|0.97|0.00|2.93|0.00|
|0|0|WELL_44497_A|1.189|0.00|1.06|0.00|3.06|0.00|
|0|0|ISAAC|2.46102|0.00|0.86|0.00|1.44|0.00|
|0|0|MT_64|7.13676|0.00|1|0.00|0.79|0.00|
|0|0|MT|11.00264|0.00|1.06|0.00|0.8|0.00|
|0|0|TWO_CMRES|133.73698|0.00|1.12|0.00|1.1|0.00|
|1|0.00398456|SPLIT_MIX_64|0.01308456|30.45|6.3|4.83|9.68|3.15|
|1|0.00603231|KISS|0.02735231|22.05|3.4|6.49|52.74|0.42|
|1|0.00735691|WELL_512_A|0.03271691|22.49|3.43|6.56|50.12|0.45|
|1|0.00744491|WELL_1024_A|0.04206491|17.70|2.97|5.96|37.38|0.47|
|1|0.01915509|JDK|0.05413509|35.38|1.86|19.02|3.29|10.75|
|1|0.00488982|XOR_SHIFT_1024_S|0.04450982|10.99|2.43|4.52|67.09|0.16|
|1|0.00413311|MWC_256|0.47337311|0.87|1.18|0.74|4.47|0.20|
|1|0.010572|WELL_19937_C|0.505032|2.09|1.2|1.74|4.51|0.46|
|1|0.01000549|WELL_19937_A|0.54464549|1.84|1.11|1.66|4.81|0.38|
|1|0.01212127|WELL_44497_B|1.11356127|1.09|0.97|1.12|2.91|0.37|
|1|0.01106587|WELL_44497_A|1.20006587|0.92|1.06|0.87|3.04|0.30|
|1|0.00597662|ISAAC|2.46699662|0.24|0.86|0.28|1.44|0.17|
|1|0.00619041|MT_64|7.14295041|0.09|1|0.09|0.79|0.11|
|1|0.00663587|MT|11.00927587|0.06|1.06|0.06|0.8|0.08|
|1|0.00458057|TWO_CMRES|133.74156057|0.00|1.12|0.00|1.1|0.00|
|10|0.0398456|SPLIT_MIX_64|0.0489456|81.41|2.42|33.64|3.32|24.52|
|10|0.0603231|KISS|0.0816431|73.89|1.8|41.05|18.34|4.03|
|10|0.0735691|WELL_512_A|0.0989291|74.37|1.81|41.09|17.24|4.31|
|10|0.0744491|WELL_1024_A|0.1090691|68.26|1.76|38.78|15.03|4.54|
|10|0.1915509|JDK|0.2265309|84.56|1.21|69.88|1.55|54.55|
|10|0.0488982|XOR_SHIFT_1024_S|0.0885182|55.24|1.72|32.12|34.23|1.61|
|10|0.0413311|MWC_256|0.5105711|8.10|1.17|6.92|4.22|1.92|
|10|0.10572|WELL_19937_C|0.60018|17.61|1.17|15.06|3.95|4.46|
|10|0.1000549|WELL_19937_A|0.6346949|15.76|1.1|14.33|4.27|3.69|
|10|0.1212127|WELL_44497_B|1.2226527|9.91|0.97|10.22|2.74|3.62|
|10|0.1106587|WELL_44497_A|1.2996587|8.51|1.05|8.11|2.89|2.95|
|10|0.0597662|ISAAC|2.5207862|2.37|0.86|2.76|1.43|1.66|
|10|0.0619041|MT_64|7.1986641|0.86|1|0.86|0.79|1.09|
|10|0.0663587|MT|11.0689987|0.60|1.06|0.57|0.8|0.75|
|10|0.0458057|TWO_CMRES|133.7827857|0.03|1.12|0.03|1.1|0.03|
|100|0.398456|SPLIT_MIX_64|0.407556|97.77|1.17|83.56|1.28|76.38|
|100|0.603231|KISS|0.624551|96.59|1.1|87.81|3.27|29.54|
|100|0.735691|WELL_512_A|0.761051|96.67|1.1|87.88|3.11|31.08|
|100|0.744491|WELL_1024_A|0.779111|95.56|1.11|86.09|2.96|32.28|
|100|1.915509|JDK|1.950489|98.21|1.02|96.28|1.06|92.65|
|100|0.488982|XOR_SHIFT_1024_S|0.528602|92.50|1.12|82.59|6.57|14.08|
|100|0.413311|MWC_256|0.882551|46.83|1.1|42.57|2.86|16.37|
|100|1.0572|WELL_19937_C|1.55166|68.13|1.06|64.28|2.14|31.84|
|100|1.000549|WELL_19937_A|1.535189|65.17|1.04|62.67|2.35|27.73|
|100|1.212127|WELL_44497_B|2.313567|52.39|0.99|52.92|1.92|27.29|
|100|1.106587|WELL_44497_A|2.295587|48.20|1.03|46.80|2.07|23.29|
|100|0.597662|ISAAC|3.058682|19.54|0.89|21.95|1.36|14.37|
|100|0.619041|MT_64|7.755801|7.98|1|7.98|0.8|9.98|
|100|0.663587|MT|11.666227|5.69|1.06|5.37|0.81|7.02|
|100|0.458057|TWO_CMRES|134.195037|0.34|1.12|0.30|1.1|0.31|
|10000|39.8456|SPLIT_MIX_64|39.8547|99.98|1|99.98|1|99.98|
|10000|60.3231|KISS|60.34442|99.96|1|99.96|1.02|98.00|
|10000|73.5691|WELL_512_A|73.59446|99.97|1|99.97|1.02|98.01|
|10000|74.4491|WELL_1024_A|74.48372|99.95|1|99.95|1.02|97.99|
|10000|191.5509|JDK|191.58588|99.98|1|99.98|1|99.98|
|10000|48.8982|XOR_SHIFT_1024_S|48.93782|99.92|1|99.92|1.06|94.26|
|10000|41.3311|MWC_256|41.80034|98.88|1|98.88|1.04|95.07|
|10000|105.72|WELL_19937_C|106.21446|99.53|1|99.53|1.02|97.58|
|10000|100.0549|WELL_19937_A|100.58954|99.47|1|99.47|1.02|97.52|
|10000|121.2127|WELL_44497_B|122.31414|99.10|1|99.10|1.02|97.16|
|10000|110.6587|WELL_44497_A|111.8477|98.94|1|98.94|1.02|97.00|
|10000|59.7662|ISAAC|62.22722|96.05|0.99|97.02|1.02|94.16|
|10000|61.9041|MT_64|69.04086|89.66|1|89.66|0.98|91.49|
|10000|66.3587|MT|77.36134|85.78|1.01|84.93|0.97|88.43|
|10000|45.8057|TWO_CMRES|179.54268|25.51|1.09|23.41|1.08|23.62|
|100000|398.456|SPLIT_MIX_64|398.4651|100.00|1|100.00|1|100.00|
|100000|603.231|KISS|603.25232|100.00|1|100.00|1|100.00|
|100000|735.691|WELL_512_A|735.71636|100.00|1|100.00|1|100.00|
|100000|744.491|WELL_1024_A|744.52562|100.00|1|100.00|1|100.00|
|100000|1915.509|JDK|1915.54398|100.00|1|100.00|1|100.00|
|100000|488.982|XOR_SHIFT_1024_S|489.02162|99.99|1|99.99|1.01|99.00|
|100000|413.311|MWC_256|413.78024|99.89|1|99.89|1|99.89|
|100000|1057.2|WELL_19937_C|1057.69446|99.95|1|99.95|1|99.95|
|100000|1000.549|WELL_19937_A|1001.08364|99.95|1|99.95|1|99.95|
|100000|1212.127|WELL_44497_B|1213.22844|99.91|1|99.91|1|99.91|
|100000|1106.587|WELL_44497_A|1107.776|99.89|1|99.89|1|99.89|
|100000|597.662|ISAAC|600.12302|99.59|1|99.59|1|99.59|
|100000|619.041|MT_64|626.17776|98.86|1|98.86|1|98.86|
|100000|663.587|MT|674.58964|98.37|1|98.37|1|98.37|
|100000|458.057|TWO_CMRES|591.79398|77.40|1.03|75.15|1.02|75.88|

 

*Creating 1 value.*

Construction time dominates. For the fastest to construct (SplitMix) the time 
generating the number is only 30% of the total time when using the *new* 
keyword, or 5% when constructing with the native seed via the factory method.

The use case here is not to generate a single random number (instead use e.g. 
{{NumberFactory.nextLong()}}) but to have a {{UniformRandomProvider}} to pass 
to a method/object that requires one. Perhaps an example should be added to the 
examples module that demonstrates how to do this using a 
{{ThreadLocal<UniformRandomProvider>}} to provide thread safety for a 
single/low usage RNG.

 

*Creating 10 values.*

The construction time is a noticable component of the total time. For the 
fastest to construct (SplitMix) the time generating the number is now 80% of 
the total time when using the *new* keyword, but mush lower at 33% when 
constructing with the native seed via the factory method. In this use case it 
will be valid to optimise construction speed.

 

*Creating 100 values.*

For the fast to construct generators the generation time is the major component 
of the run-time. All of these generators have either a primitive seed or a seed 
array with a size less than 32. The difference of using the 
{{RandomSource.create}} is noticeable and optimisation of the construction will 
still be beneficial.

Compared to the above generating 100 values using a SplitMix64 takes 80% of the 
total time when using the *new* keyword, or 84% when constructing with the 
native seed via the factory method.

The slow to construct generators (MT, MT_64, TWO_CMRES) have internal seeding 
routines that dominate total time.

The other generators MWC_256, Well family and ISAAC take 47%, 68-48% and 20% of 
the time generating numbers. These have intermediate length seeds which are 
copied in the constructor adding overhead.

Note that there is a big difference between creating a generator with a native 
seed and with no seed when not using a primitive seed as the cost to generate 
the seed is significant.

 

*Creating 10000 values.*

Only the slow to construct generators (MT, MT_64, TWO_CMRES) with internal 
seeding routines part of the algorithm are still dominated by construction cost.

The cost of seed generation is now not very noticeable.

*Creating 1000000 values.*

By this point creating without a seed has no penalty verses with a seed.

Most generators spend nearly 100% of the time generating numbers.

The slow to construct MT and MT 64 spend <2% of the time constructing. Only the 
TWO_CMRES still spends 24% of the time constructing the generator.

*It should be noted that generation is still fast. TWO_CMRES can be constructed 
from a random seed and create 1,000,000 numbers in 592 microseconds, less than 
a millisecond.*

To preempt the question: Why bother if this is so fast anyway?
 A. Because a few small changes will significantly improve speed in the use 
case of constructing short lifetime generators for use in for example array 
shuffling. And "[because it's 
there|https://blog.theclymb.com/out-there/because-its-there-the-quotable-george-mallory/]";.
  

Improvements ideas:
 * Generators with an array seed construct a new array (zero filled) and call 
the method to fill the array using the input seed. In the case where the input 
seed is the correct size then seed filling can be skipped and the seed copied 
using a call to {{Arrays.copyOf}} which should be faster as it is JVM intrinsic 
and avoids zero fill.
 * The MWC_256 is interesting as it has a seed size of 257. However the 
construction creates a temp array which is filled and then later copied to the 
state which has a size of 256. If the input seed is the correct size then this 
allocation for seed filling is redundant. This provides an optimisation.

> Create a RandomSource.create benchmark
> --------------------------------------
>
>                 Key: RNG-72
>                 URL: https://issues.apache.org/jira/browse/RNG-72
>             Project: Commons RNG
>          Issue Type: New Feature
>          Components: simple
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Minor
>              Labels: performance-benchmark
>             Fix For: 1.3
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> The recommended method to construct a {{UniformRandomProvider}} is to use, 
> e.g.:
> {code:java}
> import org.apache.commons.rng.UniformRandomProvider;
> import org.apache.commons.rng.simple.RandomSource;
> UniformRandomProvider rng = RandomSource.create(RandomSource.MWC_256);
> {code}
> The factory method knows the type of seed required for the constructor and 
> generates one as appropriate.
> This factory method could be made more efficient, in particular:
>  * Reducing synchronisation around the single source of random seed data
>  * Adding knowledge of the required seed size for arrays
>  * Changing internal data structures, e.g. {{Map<Class<?>, 
> SeedConverter<?,?>>}} can be changed to {{Map<SeedType, SeedConverter<?,?>>}} 
> using an {{EnumMap}} if a new enum {{SeedType}} was created for all the 
> supported seeds (currently 4 types).
>  * Add a new interface to replace {{SeedConverter<?,?>.convert()}} with a 
> {{.convert(int outputArraySize)}} method to allow conversions to generate 
> appropriately sized arrays. The parameter can be ignored for non-array 
> conversions but could optimise array conversions.
> This ticket is to add a JMH benchmark to compare the speed of construction of 
> all the providers using:
>  * Their native constructor
>  * {{RandomSource}} using the native seed of the correct size (calls a 
> constructor using reflection)
>  * {{RandomSource}} using a non native seed (requires seed conversion)
>  * {{RandomSource}} using no seed (requires seed generation)
> The report will be posted here. It could be added to the user guide for 
> reference.
> This work is motivated by the new {{XorShiRo}} generators in version 1.3 that 
> have a native array seed size of 2, 4, or 8. The current {{RandomSource}} 
> create method will generate a fixed seed of length 128 for seeding.



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

Reply via email to