Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-79

Benchmark methods for producing nextDouble

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.3
    • 1.3
    • core
    • None

    Description

      Benchmark the speed of methods for producing a double from a long:

      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);
      

      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.

      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:

      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)
      

      Method f2 is currently used in the NumberFactory.

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m