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

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

A more comprehensive speed test using 5 different samplers and 30 repeats of 
the timing.

Conclusions

- Approximately 1.6 - 2x faster with a slow sampler (WELL_44497_B) (computed as 
1/0.6 to 1/0.5)
- Approximately 2 - 2.5x faster with a fast sampler (SPLIT_MIX_64) (computed as 
1/0.5 to 1/0.4)
- Any empty cache does not have a time penalty

||randomSourceName||range||Method||Score||Error||Relative||
|KISS|1|runPoissonSampler|42234.32|1762.79|0.995|
|KISS|1|runPoissonSamplerCache|19535.32|1988.40|0.460|
|KISS|1|runPoissonSamplerCacheWhenEmpty|42440.81|1670.79|1.000|
|MWC_256|1|runPoissonSampler|41065.36|37.50|0.988|
|MWC_256|1|runPoissonSamplerCache|19332.02|1516.83|0.465|
|MWC_256|1|runPoissonSamplerCacheWhenEmpty|41549.41|1310.60|1.000|
|SPLIT_MIX_64|1|runPoissonSampler|38653.64|32.51|0.942|
|SPLIT_MIX_64|1|runPoissonSamplerCache|16178.99|1246.87|0.394|
|SPLIT_MIX_64|1|runPoissonSamplerCacheWhenEmpty|41017.03|1815.27|1.000|
|WELL_1024_A|1|runPoissonSampler|49440.67|3092.29|0.973|
|WELL_1024_A|1|runPoissonSamplerCache|24649.13|1471.50|0.485|
|WELL_1024_A|1|runPoissonSamplerCacheWhenEmpty|50817.60|3825.45|1.000|
|WELL_44497_B|1|runPoissonSampler|52267.09|3461.71|1.000|
|WELL_44497_B|1|runPoissonSamplerCache|26226.71|54.97|0.502|
|WELL_44497_B|1|runPoissonSamplerCacheWhenEmpty|50541.07|1028.85|0.967|
|KISS|4|runPoissonSampler|41128.02|39.48|0.981|
|KISS|4|runPoissonSamplerCache|18104.98|1023.90|0.432|
|KISS|4|runPoissonSamplerCacheWhenEmpty|41944.82|1736.54|1.000|
|MWC_256|4|runPoissonSampler|40967.31|196.96|0.972|
|MWC_256|4|runPoissonSamplerCache|19222.78|1519.90|0.456|
|MWC_256|4|runPoissonSamplerCacheWhenEmpty|42126.26|2172.58|1.000|
|SPLIT_MIX_64|4|runPoissonSampler|39024.29|1918.85|0.959|
|SPLIT_MIX_64|4|runPoissonSamplerCache|16419.52|1355.62|0.403|
|SPLIT_MIX_64|4|runPoissonSamplerCacheWhenEmpty|40696.69|1997.10|1.000|
|WELL_1024_A|4|runPoissonSampler|50246.25|3247.29|1.000|
|WELL_1024_A|4|runPoissonSamplerCache|23512.54|1540.25|0.468|
|WELL_1024_A|4|runPoissonSamplerCacheWhenEmpty|46269.05|66.92|0.921|
|WELL_44497_B|4|runPoissonSampler|51612.46|2725.12|0.964|
|WELL_44497_B|4|runPoissonSamplerCache|26627.34|1546.23|0.497|
|WELL_44497_B|4|runPoissonSamplerCacheWhenEmpty|53543.94|4113.50|1.000|
|KISS|16|runPoissonSampler|45629.70|3860.63|1.000|
|KISS|16|runPoissonSamplerCache|19361.89|1487.01|0.424|
|KISS|16|runPoissonSamplerCacheWhenEmpty|42468.50|2303.46|0.931|
|MWC_256|16|runPoissonSampler|39672.39|34.22|0.940|
|MWC_256|16|runPoissonSamplerCache|17991.17|1565.10|0.426|
|MWC_256|16|runPoissonSamplerCacheWhenEmpty|42199.80|2969.12|1.000|
|SPLIT_MIX_64|16|runPoissonSampler|40726.63|2903.56|1.000|
|SPLIT_MIX_64|16|runPoissonSamplerCache|15014.47|40.97|0.369|
|SPLIT_MIX_64|16|runPoissonSamplerCacheWhenEmpty|39758.29|1658.82|0.976|
|WELL_1024_A|16|runPoissonSampler|45726.64|2410.34|0.990|
|WELL_1024_A|16|runPoissonSamplerCache|23759.82|1254.68|0.514|
|WELL_1024_A|16|runPoissonSamplerCacheWhenEmpty|46210.49|46.49|1.000|
|WELL_44497_B|16|runPoissonSampler|50814.02|2239.43|1.000|
|WELL_44497_B|16|runPoissonSamplerCache|26829.46|1645.74|0.528|
|WELL_44497_B|16|runPoissonSamplerCacheWhenEmpty|48915.91|130.36|0.963|
|KISS|64|runPoissonSampler|41612.96|1814.84|1.000|
|KISS|64|runPoissonSamplerCache|18750.37|1565.55|0.451|
|KISS|64|runPoissonSamplerCacheWhenEmpty|40432.05|56.09|0.972|
|MWC_256|64|runPoissonSampler|41427.43|2557.89|1.000|
|MWC_256|64|runPoissonSamplerCache|17552.39|1130.28|0.424|
|MWC_256|64|runPoissonSamplerCacheWhenEmpty|40821.57|1876.39|0.985|
|SPLIT_MIX_64|64|runPoissonSampler|38646.17|39.21|0.931|
|SPLIT_MIX_64|64|runPoissonSamplerCache|16232.45|1291.95|0.391|
|SPLIT_MIX_64|64|runPoissonSamplerCacheWhenEmpty|41517.65|2653.60|1.000|
|WELL_1024_A|64|runPoissonSampler|46959.27|3136.53|1.000|
|WELL_1024_A|64|runPoissonSamplerCache|23874.08|2373.48|0.508|
|WELL_1024_A|64|runPoissonSamplerCacheWhenEmpty|46856.69|2219.90|0.998|
|WELL_44497_B|64|runPoissonSampler|48432.79|281.38|0.972|
|WELL_44497_B|64|runPoissonSamplerCache|28390.82|2218.50|0.570|
|WELL_44497_B|64|runPoissonSamplerCacheWhenEmpty|49834.53|2378.21|1.000|
|KISS|256|runPoissonSampler|41209.56|1899.56|0.949|
|KISS|256|runPoissonSamplerCache|18262.79|1441.24|0.420|
|KISS|256|runPoissonSamplerCacheWhenEmpty|43436.55|2961.43|1.000|
|MWC_256|256|runPoissonSampler|39330.66|56.23|0.905|
|MWC_256|256|runPoissonSamplerCache|16066.98|32.66|0.370|
|MWC_256|256|runPoissonSamplerCacheWhenEmpty|43471.03|2987.62|1.000|
|SPLIT_MIX_64|256|runPoissonSampler|37933.20|33.58|0.911|
|SPLIT_MIX_64|256|runPoissonSamplerCache|14697.77|680.43|0.353|
|SPLIT_MIX_64|256|runPoissonSamplerCacheWhenEmpty|41643.01|3198.04|1.000|
|WELL_1024_A|256|runPoissonSampler|47902.53|4096.85|1.000|
|WELL_1024_A|256|runPoissonSamplerCache|23860.03|1933.58|0.498|
|WELL_1024_A|256|runPoissonSamplerCacheWhenEmpty|46526.57|2362.18|0.971|
|WELL_44497_B|256|runPoissonSampler|49828.88|2616.53|1.000|
|WELL_44497_B|256|runPoissonSamplerCache|25532.62|1562.00|0.512|
|WELL_44497_B|256|runPoissonSamplerCacheWhenEmpty|48757.61|1478.88|0.979|
|KISS|1024|runPoissonSampler|41457.70|2407.54|1.000|
|KISS|1024|runPoissonSamplerCache|18827.61|1556.78|0.454|
|KISS|1024|runPoissonSamplerCacheWhenEmpty|40893.37|1731.42|0.986|
|MWC_256|1024|runPoissonSampler|39636.34|1535.31|0.952|
|MWC_256|1024|runPoissonSamplerCache|18214.00|1652.84|0.438|
|MWC_256|1024|runPoissonSamplerCacheWhenEmpty|41620.86|2450.26|1.000|
|SPLIT_MIX_64|1024|runPoissonSampler|37913.51|1195.07|0.947|
|SPLIT_MIX_64|1024|runPoissonSamplerCache|14940.48|43.61|0.373|
|SPLIT_MIX_64|1024|runPoissonSamplerCacheWhenEmpty|40047.43|3156.92|1.000|
|WELL_1024_A|1024|runPoissonSampler|44162.82|30.46|0.952|
|WELL_1024_A|1024|runPoissonSamplerCache|22046.85|999.12|0.475|
|WELL_1024_A|1024|runPoissonSamplerCacheWhenEmpty|46368.22|2646.79|1.000|
|WELL_44497_B|1024|runPoissonSampler|51266.86|3043.21|1.000|
|WELL_44497_B|1024|runPoissonSamplerCache|27389.41|2140.52|0.534|
|WELL_44497_B|1024|runPoissonSamplerCacheWhenEmpty|47536.47|42.87|0.927|
|KISS|4096|runPoissonSampler|42091.24|2953.07|1.000|
|KISS|4096|runPoissonSamplerCache|19027.55|1454.77|0.452|
|KISS|4096|runPoissonSamplerCacheWhenEmpty|40113.74|1064.72|0.953|
|MWC_256|4096|runPoissonSampler|39424.34|1543.87|0.889|
|MWC_256|4096|runPoissonSamplerCache|19917.59|1902.02|0.449|
|MWC_256|4096|runPoissonSamplerCacheWhenEmpty|44345.83|3623.52|1.000|
|SPLIT_MIX_64|4096|runPoissonSampler|38139.52|1608.12|0.956|
|SPLIT_MIX_64|4096|runPoissonSamplerCache|19086.41|2196.48|0.478|
|SPLIT_MIX_64|4096|runPoissonSamplerCacheWhenEmpty|39906.79|2317.68|1.000|
|WELL_1024_A|4096|runPoissonSampler|46756.98|2895.78|1.000|
|WELL_1024_A|4096|runPoissonSamplerCache|21970.86|553.69|0.470|
|WELL_1024_A|4096|runPoissonSamplerCacheWhenEmpty|45395.83|2206.01|0.971|
|WELL_44497_B|4096|runPoissonSampler|47249.37|67.00|0.996|
|WELL_44497_B|4096|runPoissonSamplerCache|27313.23|1946.59|0.576|
|WELL_44497_B|4096|runPoissonSamplerCacheWhenEmpty|47441.17|37.31|1.000|







> PoissonSampler single use speed improvements using a cache
> ----------------------------------------------------------
>
>                 Key: RNG-51
>                 URL: https://issues.apache.org/jira/browse/RNG-51
>             Project: Commons RNG
>          Issue Type: Improvement
>    Affects Versions: 1.1
>            Reporter: Alex D Herbert
>            Priority: Minor
>              Labels: performance
>
> This improvement is a follow on from RNG-50.
> That improved the PoissonSampler by splitting it into two samplers for the 
> different algorithms (SmallMeanPoissonSampler and LargeMeanPoissonSampler) 
> and moving initialisation computations from the sample method into the 
> constructor. This improved the speed of repeat use of the same sampler by up 
> to 3-fold. It does not effect single-use of a sampler.
> In the case of the LargeMeanPoissonSampler the initialisation 'state' 
> computed within the constructor involves 2 Math.log, 2 Math.exp, 2 Math.sqrt 
> and 1 logFactorial computations. If the sampler is used to generate only 1 
> sample then the cost of computing the state is a significant portion of the 
> sample time.
> However the state is not unique to the mean of the Poisson distribution but 
> the {{(int)Math.floor(mean)}}. This means the initialisation state can be 
> shared and reused by PoissonSamplers with different means.
> This was demonstrated using a JMH benchmark speed test comparing the standard 
> PoissonSampler verses a PoissonSamplerCache that can store the initialisation 
> state of the PoissonSampler.
> For single-use Poisson samples with a mean within a known range the cache can 
> provide 1.3 to 2x speed-up as initialisation state can be reused.
> The original benchmark was performed using Version 1.0. The Version 1.1. 
> samplers use a new faster Gaussian sampler internally. So the benchmark 
> should be repeated for Version 1.1.
> The test project containing the V1.0 JMH benchmark is here: 
> [poisson-sampler-test-code|https://github.com/aherbert/poisson-sampler-test-code]
> I propose to update this project to reference V1.1 of Commons RNG and repeat 
> the test of the PoissonSamplerCache. Results will be posted when available. 



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

Reply via email to