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

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

Here is the data comparing the construction through the factory with 
construction using the *new* keyword.

*With a pre-build seed*:
|RNG|createNativeSeed|new + NativeSeed|Relative|Seed size|Seed type|
|SPLIT_MIX_64|10.555|2.725|3.874|1|long|
|XO_RO_SHI_RO_64_SS|11.410|2.772|4.116|2|int|
|XO_RO_SHI_RO_64_S|11.430|2.778|4.114|2|int|
|XO_SHI_RO_128_SS|12.175|3.759|3.239|4|int|
|XO_RO_SHI_RO_128_SS|12.216|3.939|3.101|2|long|
|XO_RO_SHI_RO_128_PLUS|12.347|4.069|3.034|2|long|
|XO_SHI_RO_128_PLUS|12.147|4.796|2.533|4|int|
|XO_SHI_RO_256_PLUS|13.326|5.815|2.292|4|long|
|XO_SHI_RO_256_SS|13.363|5.946|2.247|4|long|
|KISS|23.082|9.233|2.500|4|int|
|XO_SHI_RO_512_PLUS|18.215|10.172|1.791|8|long|
|XO_SHI_RO_512_SS|18.595|10.731|1.733|8|long|
|JDK|24.610|12.654|1.945|1|long|
|WELL_512_A|26.347|13.353|1.973|16|int|
|WELL_1024_A|34.587|20.974|1.649|32|int|
|XOR_SHIFT_1024_S_PHI|36.171|21.823|1.657|16|long|
|XOR_SHIFT_1024_S|36.644|21.901|1.673|16|long|
|WELL_19937_A|335.859|310.806|1.081|624|int|
|WELL_19937_C|332.835|313.929|1.060|624|int|
|MWC_256|322.355|325.020|0.992|257|int|
|WELL_44497_A|638.771|618.200|1.033|1391|int|
|WELL_44497_B|645.603|629.002|1.026|1391|int|
|ISAAC|1835.391|1838.906|0.998|256|int|
|MT_64|5179.458|5160.515|1.004|312|long|
|MT|8644.216|8729.320|0.990|624|int|
|TWO_CMRES|149571.119|100527.616|1.488|1|int|

 
 The TWO_CMRES data is an anomaly. The time to build the RNG is very large. The 
time for the constructor invocation should not matter. This should be 
investigated as using *new* here is the biggest benefit in the table. However 
the units are ns so this is a difference of .5 milliseconds in practice.

For the rest of the generators the cost of the factory method is progressively 
swamped by the rest of the work to make the generator as the seed gets larger. 
Using the *new* keyword is only relatively noticeable for very small seeds when 
the RNG has no extra work in the constructor. In practice this will not be 
noticed since it would require creating thousands of short lifetime generators 
with simple pre-built seeds.

*With seed built using the SeedFactory*. I only include those with small seeds 
as I do not have data for seeds larger than 128:
|RNG|createNullSeed|new + SeedFactory|Relative|Seed size|Seed type|
|SPLIT_MIX_64|85.635|58.978|1.452|1|long|
|XO_RO_SHI_RO_64_SS|81.631|64.035|1.275|2|int|
|XO_RO_SHI_RO_64_S|85.723|64.042|1.339|2|int|
|JDK|95.676|68.908|1.388|1|long|
|XO_SHI_RO_128_SS|104.708|82.973|1.262|4|int|
|XO_SHI_RO_128_PLUS|103.972|84.010|1.238|4|int|
|XO_RO_SHI_RO_128_SS|117.396|85.957|1.366|2|long|
|XO_RO_SHI_RO_128_PLUS|110.042|86.088|1.278|2|long|
|KISS|112.247|88.447|1.269|4|int|
|XO_SHI_RO_256_PLUS|150.657|109.504|1.376|4|long|
|XO_SHI_RO_256_SS|141.544|115.450|1.226|4|long|
|WELL_512_A|254.421|179.110|1.420|16|int|
|XO_SHI_RO_512_PLUS|217.515|186.256|1.168|8|long|
|XO_SHI_RO_512_SS|217.241|186.816|1.163|8|long|
|XOR_SHIFT_1024_S_PHI|372.309|330.121|1.128|16|long|
|XOR_SHIFT_1024_S|368.234|330.200|1.115|16|long|
|WELL_1024_A|596.979|352.489|1.694|32|int|
|TWO_CMRES|149183.341|100574.526|1.483|1|int|

 
 WELL_1024_A is an outlier. The rest of the generators all are built in 
comparable time to using the *new* keyword.

Comparison of the tables show that generating the seed takes the majority of 
time for construction of a generator.

For the normal use case of a long-lived generator then construction cost is not 
a factor on run-time.

If a use case is for a generator that is very short lived (<100 deviates) and 
then discarded where speed is a priority then the recommendation is to create 
using the *new* keyword a small state generator and build the state using a 
fast thread-safe method to create a seed. A separate Jira ticket will discuss 
options for adding such a method to the SeedFactory.

The fastest generator to create is the SplitMix. There is a Jira ticket to add 
a primitive constructor to this generator RNG-76 which shows that auto-boxing 
is a significant part of construction. The other generators with small state 
have array seeds or constructors with primitive arguments so auto-boxing is not 
a factor.

Alternatively ThreadLocalRandom from JDK 1.7 would fit this use case ideally as 
it is designed for this purpose. It does not implement UniformRandomProvider so 
would have to be wrapped to be used with anything requiring that interface.

 

> Improve the speed of the RandomSource create method.
> ----------------------------------------------------
>
>                 Key: RNG-75
>                 URL: https://issues.apache.org/jira/browse/RNG-75
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: simple
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: large.jpg, long.jpg, small.jpg
>
>
> Update the {{o.a.c.rng.simple.internal}} package to improve the construction 
> speed of random generators.
> Areas identified by the construction benchmark 
> [RNG-72|https://issues.apache.org/jira/projects/RNG/issues/RNG-72] include:
> * Update the {{RandomSourceInternal}} to know the desired size for the native 
> seed
> * Update the {{SeedFactory}} for faster {{byte[]}} conversions
> * Remove the use of reflection for fast seeding generators
> It is intended that all changes made are non-destructive to the quality of 
> any generated seed.



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

Reply via email to