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=22973>. 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=22973 [collections] [PATCH] patch to reduce object creation in CollectionUtils Summary: [collections] [PATCH] patch to reduce object creation in CollectionUtils Product: Commons Version: Nightly Builds Platform: Other OS/Version: Other Status: NEW Severity: Minor Priority: Other Component: Collections AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] The attached patch reduces the number of Integer objects created when invoking CollectionUtils.getCardinalityMap(final Collection col). The number of Integers created is reduced by the count of unique objects within col. The patch does not change the basic algorithm so the simplicity of the method is not lost. The change was profiled with the class below. These are the absolute times for JDK 1.3.1_04 and 1.4.1_03 1.4 1.3 pre: 168267 153849 post: 164473 150866 and normalised to the pre version for each JDK 1.4 1.3 pre: 1.00 1.00 post: 0.98 0.98 so there was only a minor speed difference however the reduction in the number of created objects has a memory use advantage. It was surprising to see that JDK 1.4.1 was slower than 1.3.1, in this limited test. The binaries were compiled with JDK 1.4.1. 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 = 1001 ; 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]