Java on the two Map conducted performance testing, and try to optimize its own
Abstract: The Map of the two java provide the performance tests, and to try its own optimization
Content: from foxcrane the blog: http://www.matrix.org.cn/blog/foxcrane
Of the two Map java the performance test results can be found 100,000 key to the Map View is not very slow, probably 50 - 60 ms
Also intends to do their own manual performance optimization, the prefix will be different from several small KEY MAP found no performance difference, in wonder. .
Separate into several small MAP, and then inside a small can also points points points points, to form a tree in alphabetical search
Suddenly thought, Java Pro have said in the article Map series of built-in performance optimization, and that seems to me that this thinking is the same
Find information see (http://www.fawcette.com/china/XmlFile.aspx?ID=8&page=1), a real case, Hey, but not profound impression last saw this come up with their own , the impression is really profound, and it has proved that heroes see strategies (Oh)
/ **
* Map Series Performance Testing
* /
Import java.util .*;
Public class MapTest
(
Public static void main (String ags []) (
Test2 ();
System.out.println ("—–");
Test1 ();
)
Public static void test1 () (
Map m = new HashMap ();
Long t0 = System.currentTimeMillis ();
For (int i = 0; i <99999; i + +)
(
M.put ( "aa.bb.to.pub." + I + "12345asfsdfVO", i + "value");
)
Long t1 = System.currentTimeMillis ();
System.out.println (t1-t0);
/ / System.out.println (m.get ( "8888key"));
For (int i = 0; i <99999; i + +)
(
M.get ( "aa.bb.to.pub." + I + "12345asfsdfVO");
)
Long t2 = System.currentTimeMillis ();
System.out.println (t1-t2);
)
Public static void test2 () (
Map m = new HashMap ();
M.put ( "aa.bb.ao" new HashMap ());
M.put ( "aa.bb.do" new HashMap ());
M.put ( "aa.bb.wo" new HashMap ());
M.put ( "aa.bb.po" new HashMap ());
M.put ( "aa.bb.io" new HashMap ());
M.put ( "aa.bb.oo" new HashMap ());
M.put ( "aa.bb.bo" new HashMap ());
M.put ( "aa.bb.to" new HashMap ());
M.put ( "aa.bb.yo" new HashMap ());
M.put ( "aa.bb.ro" new HashMap ());
Long t0 = System.currentTimeMillis ();
For (int i = 10; i <20; i + +)
(
For (int k = 1; k <5; k + +) / / 10 modules, compared probability of five modules
If ( "aa.bb.to.pub.12345headerVO." StartsWith ( "aa.bb.to"));
/ / Below assumptions upside results of this comparison: the beginning aa.bb.to
For (int j = 1000; j <2000; j + +) / / each module, there are 1000
((Map) m.get ( "aa.bb.to")). Put ( "aa.bb.to.pub." + J + "12345asfsdfVO", "value");
)
Long t1 = System.currentTimeMillis ();
System.out.println ( "Input time:" + (t1-t0));
/ / System.out.println (m.get ( "8888key"));
For (int i = 10; i <20; i + +)
(
For (int k = 1; k <5; k + +) / / 10 modules, compared probability of five modules
If ( "aa.bb.to.pub.12345asfsdfVO." StartsWith ( "aa.bb.to"));
For (int j = 1000; j <2000; j + +)
((Map) m.get ( "aa.bb.to")). Get ( "aa.bb.to.pub." + J + "12345asfsdfVO");
)
Long t2 = System.currentTimeMillis ();
System.out.println ( "Find time:" + (t1-t2));
)
);
↑ Back
Tags: Map, Performance






