go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Observations:
 
Subject: Observations:
Author: EricJ
In response to: Dynamic Collection Sorting: java.util.TreeSet
Posted on: 02/17/2009 09:14:39 PM


1) The static way is faster;
2) The static way is more memory efficient.


 

> On 02/17/2009 09:00:37 PM EricJ wrote:


public class DynamicSorting
{
    public static void main(String[] argv)
    {
        long t1, t2;
        int max = 1000000;
		
        t1=System.currentTimeMillis();

        TreeSet mySet = new TreeSet();
        for(int i=0; i<max; i++){
            mySet.add("ABCDEFG"+Math.random()*100000);
        }		
		
        t2=System.currentTimeMillis();
		
        Runtime rt = Runtime.getRuntime();
        long memoryUsed = rt.totalMemory() - rt.freeMemory();
        System.out.println(mySet.first());
        System.out.println("Time consumed="+(t2-t1)+" (ms)   Memory used="+memoryUsed+ "(bytes)" );
    	
    }
}



Here is the output:

ABCDEFG0.07930068373074306
Time consumed=17328 (ms) Memory used=124260248(bytes)





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.