Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-642

Performance of nextInt(int) in BitsStreamGenerator can be improved

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0, 2.1, 2.2
    • Fix Version/s: 3.0
    • Labels:
      None

      Description

      The code used to implement this method in Apache Harmony's Random class performs better with the Mersenne and Well generators as bit sources as well as the JDK generator. Here are some benchmark testing results ("orginal" is the current code):

      nextInt(10) comparison - JDK generator (runs per timed block: 100000, timed blocks: 1000)
      original value = 10: 5.417883e-05 (1.010215e-05) ms
      harmony value = 10: 3.808923e-05 (1.090630e-05) ms
      nextInt(100) comparison - JDK generator (runs per timed block: 100000, timed blocks: 1000)
      original value = 100: 4.602311e-05 (5.075280e-06) ms
      harmony value = 100: 3.771343e-05 (5.836102e-06) ms
      nextInt(10000) comparison - JDK generator (runs per timed block: 100000, timed blocks: 1000)
      original value = 10000: 5.317242e-05 (5.527069e-06) ms
      harmony value = 10000: 3.676283e-05 (5.062836e-06) ms
      nextInt(32) comparison - JDK generator (runs per timed block: 100000, timed blocks: 1000)
      original value = 32: 6.225222e-05 (1.143497e-05) ms
      harmony value = 32: 3.875278e-05 (6.099984e-06) ms

      nextInt(10) comparison - Well1024a (runs per timed block: 100000, timed blocks: 1000)
      original value = 10: 4.365601e-05 (1.013942e-05) ms
      harmony value = 10: 4.141704e-05 (1.778676e-05) ms
      nextInt(100) comparison - Well1024a (runs per timed block: 100000, timed blocks: 1000)
      original value = 100: 3.579893e-05 (4.670346e-06) ms
      harmony value = 100: 3.474323e-05 (5.273507e-06) ms
      nextInt(10000) comparison - Well1024a (runs per timed block: 100000, timed blocks: 1000)
      original value = 10000: 4.431216e-05 (5.654163e-06) ms
      harmony value = 10000: 3.440765e-05 (4.282874e-06) ms
      nextInt(32) comparison - Well1024a (runs per timed block: 100000, timed blocks: 1000)
      original value = 32: 5.080220e-05 (7.276901e-06) ms
      harmony value = 32: 2.958944e-05 (1.091995e-05) ms

      nextInt(10) comparison - MersenneTwister (runs per timed block: 100000, timed blocks: 1000)
      original value = 10: 4.365044e-05 (1.284578e-05) ms
      harmony value = 10: 3.199023e-05 (7.170367e-06) ms
      nextInt(100) comparison - MersenneTwister (runs per timed block: 100000, timed blocks: 1000)
      original value = 100: 3.488505e-05 (4.822188e-06) ms
      harmony value = 100: 3.145389e-05 (5.290716e-06) ms
      nextInt(10000) comparison - MersenneTwister (runs per timed block: 100000, timed blocks: 1000)
      original value = 10000: 4.468017e-05 (1.086927e-05) ms
      harmony value = 10000: 3.274545e-05 (2.059499e-05) ms
      nextInt(32) comparison - MersenneTwister (runs per timed block: 100000, timed blocks: 1000)
      original value = 32: 5.129467e-05 (6.652250e-06) ms
      harmony value = 32: 2.569880e-05 (8.063487e-06) ms

        Attachments

        1. microbenchmarks.txt
          4 kB
          Phil Steitz

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              psteitz Phil Steitz
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: