[
https://issues.apache.org/jira/browse/RNG-87?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16802234#comment-16802234
]
Alex D Herbert commented on RNG-87:
-----------------------------------
Back to the macbook:
||JDK||numValues||randomSourceName||Method||Score||Error||Median||Rel
Score||Rel Median||
|1.8.0_131-b11|1000000|MWC_256|nextDouble|4543.275|118.358|4543.954|1.00|1.00|
|1.8.0_131-b11|1000000|MWC_256B|nextDouble|2891.017|74.989|2891.362|0.64|0.64|
|1.8.0_131-b11|1000000|MWC_256C|nextDouble|2506.899|52.004|2506.648|0.55|0.55|
|1.8.0_131-b11|1000000|MWC_256|nextFloat|3511.285|55.296|3510.31|1.00|1.00|
|1.8.0_131-b11|1000000|MWC_256B|nextFloat|1405.518|18.7|1404.727|0.40|0.40|
|1.8.0_131-b11|1000000|MWC_256C|nextFloat|1322.63|37.467|1321.137|0.38|0.38|
|1.8.0_131-b11|1000000|MWC_256|nextInt|2341.24|34.479|2344.177|1.00|1.00|
|1.8.0_131-b11|1000000|MWC_256B|nextInt|1336.717|51.83|1331.971|0.57|0.57|
|1.8.0_131-b11|1000000|MWC_256C|nextInt|1322.943|21.374|1320.708|0.57|0.56|
|1.8.0_131-b11|1000000|MWC_256|nextLong|4289.15|84.313|4293.914|1.00|1.00|
|1.8.0_131-b11|1000000|MWC_256B|nextLong|2907.705|205.349|2891.066|0.68|0.67|
|1.8.0_131-b11|1000000|MWC_256C|nextLong|2493.634|53.093|2490.517|0.58|0.58|
|11.0.2|1000000|MWC_256|nextDouble|4577.002|72.29|4577.492|1.00|1.00|
|11.0.2|1000000|MWC_256B|nextDouble|2662.361|32.606|2664.836|0.58|0.58|
|11.0.2|1000000|MWC_256C|nextDouble|2516.482|34.592|2511.581|0.55|0.55|
|11.0.2|1000000|MWC_256|nextFloat|3485.658|75.996|3477.169|1.00|1.00|
|11.0.2|1000000|MWC_256B|nextFloat|1331.548|36.101|1329.94|0.38|0.38|
|11.0.2|1000000|MWC_256C|nextFloat|1318.171|18.864|1319.946|0.38|0.38|
|11.0.2|1000000|MWC_256|nextInt|2600.879|22.983|2601.49|1.00|1.00|
|11.0.2|1000000|MWC_256B|nextInt|1325.055|12.014|1325.794|0.51|0.51|
|11.0.2|1000000|MWC_256C|nextInt|1316.405|17.051|1314.804|0.51|0.51|
|11.0.2|1000000|MWC_256|nextLong|4345.139|143.535|4325.858|1.00|1.00|
|11.0.2|1000000|MWC_256B|nextLong|2725.439|50.886|2721.917|0.63|0.63|
|11.0.2|1000000|MWC_256C|nextLong|2497.082|39.163|2500.82|0.57|0.58|
Same conclusion:
MWC_256C is better here. It seems the same for int/float as MWC_256B and is
faster for long/double.
> MultiplyWithCarry256
> --------------------
>
> Key: RNG-87
> URL: https://issues.apache.org/jira/browse/RNG-87
> Project: Commons RNG
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.3
> Reporter: Alex D Herbert
> Assignee: Alex D Herbert
> Priority: Minor
> Labels: performance
> Time Spent: 20m
> Remaining Estimate: 0h
>
> The {{MultiplyWithCarry256}} currently uses a length 256 array for internal
> state. This is cycled through continuously. The current implementation
> refills the state every 256 calls to next:
> {code:java}
> public int next() {
> if (index == Q_SIZE) { // Whole state used up.
> // Refill.
> for (int i = 0; i < Q_SIZE; i++) {
> final long t = A * (state[i] & 0xffffffffL) + carry;
> carry = (int) (t >> 32);
> state[i] = (int) t;
> }
> // Reset current index.
> index = 0;
> }
> return state[index++];
> }
> {code}
> This can be changed to continuously update the state for only a single index
> on each call to next:
> {code:java}
> public int next() {
> // Produce an index in the range 0-255
> final int i = index++ & 0xFF;
> final long t = A * (state[i] & 0xffffffffL) + carry;
> carry = (int) (t >> 32);
> return state[i] = (int) t;
> }
> {code}
> This avoids an {{if}} statement check and *marginally* improves performance.
> It has the advantage of not advancing the state further ahead than necessary.
> MWC_256B is the new version. JMH results from the GenerationPerformance
> benchmark.
> {noformat}
> openjdk version "1.8.0_191"
> OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
> OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
> {noformat}
> ||numValues||randomSourceName||Method||Score||Error||Median||
> |1|SPLIT_MIX_64|nextInt|0.00478|4.45e-05|0.00477|
> |1|MWC_256|nextInt|0.00521|1.69e-05|0.00521|
> |1|MWC_256B|nextInt|0.00519|0.000321|0.00512|
> |100|SPLIT_MIX_64|nextInt|0.421|0.0131|0.418|
> |100|MWC_256|nextInt|0.452|0.000968|0.452|
> |100|MWC_256B|nextInt|0.443|0.00183|0.442|
> |10000|SPLIT_MIX_64|nextInt|41.7|0.0725|41.7|
> |10000|MWC_256|nextInt|44.5|2.25|43.9|
> |10000|MWC_256B|nextInt|42.6|0.037|42.6|
> |1000000|SPLIT_MIX_64|nextInt|3.77e+03|21.2|3.77e+03|
> |1000000|MWC_256|nextInt|4.16e+03|12.8|4.16e+03|
> |1000000|MWC_256B|nextInt|3.98e+03|120|3.96e+03|
> {noformat}
> java version "11.0.2" 2019-01-15 LTS
> Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
> Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
> {noformat}
> ||numValues||randomSourceName||Method||Score||Error||Median||
> |1|SPLIT_MIX_64|nextInt|0.00469|4.98e-06|0.00469|
> |1|MWC_256|nextInt|0.00553|2.09e-05|0.00553|
> |1|MWC_256B|nextInt|0.00493|4.32e-05|0.00492|
> |100|SPLIT_MIX_64|nextInt|0.435|0.000624|0.435|
> |100|MWC_256|nextInt|0.467|0.00284|0.466|
> |100|MWC_256B|nextInt|0.455|0.00105|0.455|
> |10000|SPLIT_MIX_64|nextInt|43|4.94|41.9|
> |10000|MWC_256|nextInt|45.8|0.132|45.8|
> |10000|MWC_256B|nextInt|43|0.033|43|
> |1000000|SPLIT_MIX_64|nextInt|3.7e+03|7.88|3.7e+03|
> |1000000|MWC_256|nextInt|4.17e+03|45.3|4.15e+03|
> |1000000|MWC_256B|nextInt|4.12e+03|4.76|4.12e+03|
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)