commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex D Herbert (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (RNG-79) Benchmark methods for producing nextDouble
Date Mon, 04 Mar 2019 21:53:00 GMT

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

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

There was not any difference!

I have added a baseline method which was generation of a linear sequence of {{long}} or {{int}}.
The other methods are as described in the header. These are just applied to the generated
long.

Benchmark is 5 iterations using Throughput mode. Timings are {{ops/us}}, higher is better.
||Method||Score||Error||Median||
|nextDoubleBaseline|437|18.5|438|
|nextDoubleUsingBitsToDouble|380|25.3|381|
|nextDoubleUsingMultiply52bits|381|12|381|
|nextDoubleUsingMultiply53bits|385|7.59|384|
|nextFloatBaseline|432|17|433|
|nextFloatUsingBitsToFloat|384|12.2|383|
|nextFloatUsingMultiply23bits|380|12.3|381|
|nextFloatUsingMultiply24bits|385|6.62|386|

Code here: [PR 28 |https://github.com/apache/commons-rng/pull/28]

I added the method for generation of {{float}} or {{double}} to the {{NumberFactory}} unit
test. This is just to show they work to compute in the range 0-1.

Note that the test shows that all methods are not capable of computing *1.0*. The closest
is 0.9999999999999999 from the multiply 53-bits method. The other two are 0.9999999999999998.
E.g.

{noformat}
0.9999999999999999
0.9999999999999998
{noformat}

> Benchmark methods for producing nextDouble
> ------------------------------------------
>
>                 Key: RNG-79
>                 URL: https://issues.apache.org/jira/browse/RNG-79
>             Project: Commons RNG
>          Issue Type: New Feature
>          Components: core
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Benchmark the speed of methods for producing a {{double}} from a {{long}}:
> {code:java}
> long v;
> double d1 = Double.longBitsToDouble(0x3FFL << 52 | v >>> 12) - 1.0;
> double d2 = (v >>> 12) * 0x1.0p-52d; // 1.0 / (1L << 52);
> double d3 = (v >>> 11) * 0x1.0p-53d; // 1.0 / (1L << 53);
> {code}
> Method d1 and d2 are both currently employed in the {{NumberFactory}} (makeDouble(int,int)
and makeDouble(long)). However they suffer from producing a double whose least significant
bit is always 0, i.e. they produce half of all possible double values from 0-1. This is discussed
in the reference for the [XorShiRo generators|http://xoshiro.di.unimi.it/].
> This task will benchmark the methods using JMH. A switch to method d3 may be appropriate
as it generates more values. This is the method employed in JDK 1.7 ThreadLocalRandom.
> A similar analysis can be made for producing a float:
> {code:java}
> int v;
> double f1 = Float.intBitsToFloat(0x7f << 23 | v >>> 9) - 1.0f;
> double f2 = (v >>> 9) * 0x1.0p-23f; // 1.0f / (1 << 23);
> double f3 = (v >>> 8) * 0x1.0p-24f; // 1.0f / (1 << 24)
> {code}
> Method f2 is currently used in the {{NumberFactory}}.



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

Mime
View raw message