The tests were performed in JDK 1.4.2 and JDK 1.5, but the test results were unexpected. The same code, the use of generic performance has a small part of the decline.
It seems that Sun has to add hard to make JDK 1.5 become real "Tiger".
/ *
* Create a date 2004-10-6
* Author 2002pp
* /
Package code.test;
Import java.util.arraylist;
Import java.util.list;
/ **
* @Author 2002pp
* Under JDK 1.4.2
* /
Public Class PerformanceTestSt
{
/ ** Creates a new instance of performancetest * /
Public PerformanceTest ()
{
}
Public static void main (string [] args)
{
List list = new arraylist ();
Long beforeadd = system.currenttimemillis ();
INT end = 100000;
For (int i = 0; i { List.add (new integer (i)); } Long Afteradd = system.currenttimemillis (); For (int J = 0; j { Integer integer = (integer) list.get (j); } Long afterget = system.currenttimemillis (); Double Addtime = (Afteradd - BeForeAdd) / 1000.0d; Double getTime = (afterget - instradd) / 1000.0d; System.out.println ( "java.version =" system.getproperty ("java.version")); System.out.println ("Add Time:" AddTime); System.out.println ("GET Time:" GetTime); } } Result: java.version = 1.4.2 ADD Time: 0.125 GET time consumption: 0.016 / * * Create a date 2004-10-6 * Author 2002pp * / Package code.test; Import java.util.arraylist; Import java.util.list; / ** * @Author 2002pp * Under JDK 1.5 * / Public Class PerformanceTestSt { / ** Creates a new instance of performancetest * / Public PerformanceTest () { } Public static void main (String [] args) { List Long beforeadd = system.currenttimemillis (); INT end = 100000; For (INT I = 0; i List.add (new integer (i)); } Long Afteradd = system.currenttimemillis (); For (int J = 0; j } Long afterget = system.currenttimemillis (); System.out.println ("java.version =" system.getproperty ("java.version")); Double Addtime = (Afteradd-BeforeAdd) / 1000.0d; Double getTime = (afterget -Afteradd) / 1000.0d; System.out.println ("Add Time:" AddTime); System.out.println ("GET Time:" GetTime); } } Result: java.version = 1.5.0 ADD time consumption: 0.14 GET time consumption: 0.016