DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23004>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23004

[collections][PATCH] CollectionUtils.getFreq optimization

           Summary: [collections][PATCH] CollectionUtils.getFreq
                    optimization
           Product: Commons
           Version: Nightly Builds
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Collections
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


The attached patch improves the performance of CollectionUtils.getFreq(Object,
Map) by using a test in place of a thrown exception.

The effect of the change was measured with the class below. These are the times
for the Sun JDK 1.4.1_03 on Red Hat Linux 8.0

pre-optimization:   122534
post-optimization:  104637

The patch reduced the time to run the test to 85% of the original.

The also patch removes a catch of NoSuchElementException which, as far as I can
tell, was unnecessary in the original code.

This is the test class:

import org.apache.commons.collections.CollectionUtils ;

import java.util.*;

public class CollectionUtilsTest {


    Set a ;
    Set b ;
    Set c ;

    Collection cols []  ;

    long startMillis ;
    void init () {

        a = new HashSet () ;
        for ( int i = 1 ; i <= 10000 ; i++ ) {
            a.add ( new Integer ( i ) ) ;
        }

        b = new HashSet () ;
        for ( int i = 5001 ; i <= 15000 ; i++ ) {
            b.add ( new Integer ( i ) ) ;
        }

        c = new HashSet () ;
        for ( int i = 10001 ; i <= 20000 ; i++ ) {
            c.add ( new Integer ( i ) ) ;
        }

        cols = new Collection [] { a, b, c } ;

        startMillis = System.currentTimeMillis () ;
    }


    void run () {

        for ( int i = 0 ; i < 3 ; i++ ) {
            for ( int j = 0 ; j < 3 ; j++ ) {
                CollectionUtils.union ( cols [ i ], cols [ j ] ) ;
                CollectionUtils.intersection ( cols [ i ], cols [ j ] ) ;
                CollectionUtils.disjunction ( cols [ i ], cols [ j ] ) ;
                CollectionUtils.subtract ( cols [ i ], cols [ j ] ) ;
            }
        }

    }


    void report () {

        System.out.println ( "Elapsed millis: " + ( System.currentTimeMillis () -
startMillis ) ) ;
    }



    public static void main ( String  [] arg ) {

        CollectionUtilsTest t = new CollectionUtilsTest () ;

        t.init () ;
        t.run () ;
        t.report () ;

    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to