XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 3.0
    • 3.1
    • None
    • ubuntu 32bits/intel-i5/java6

    Description

      The gcd(int,int) method of ArithmeticUtils seems 2 times slower than the naive approach using modulo operator. The following test code runs in 11s with current version and in 6s with the patch.
      public void testApache()

      { Random rng=new Random(0); long checksum=0; long start=System.nanoTime(); checksum+=gcd(0,Integer.MAX_VALUE); checksum+=gcd(Integer.MAX_VALUE,0); checksum+=gcd(Integer.MAX_VALUE,rng.nextInt()); for(int i=0;i<10000;i++) checksum+=gcd(rng.nextInt(),Integer.MAX_VALUE); checksum+=gcd(Integer.MAX_VALUE,Integer.MAX_VALUE); checksum+=gcd(Integer.MIN_VALUE,1<<30); checksum+=gcd(1<<30,1<<30); checksum+=gcd(3 * (1<<20),9 * (1<<15)); for(int i=0;i<30000000;i++) checksum+=gcd(rng.nextInt(),rng.nextInt()); long end=System.nanoTime(); long tns=end-start; long tms=(tns+500000)/1000000; long ts=(tms+500)/1000; System.out.println("exec time="+ts+"s, ("+tms+"ms), checksum="+checksum); assertEquals(9023314441L,checksum); }

      Attachments

        1. patchGcdInt3.txt
          6 kB
          Sebastien Riou
        2. ArithmeticUtils.java
          32 kB
          Sebastien Riou

        Activity

          People

            Unassigned Unassigned
            acapola Sebastien Riou
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

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