Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 49475 invoked from network); 20 Jan 2003 16:06:23 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 20 Jan 2003 16:06:22 -0000 Received: (qmail 15146 invoked by uid 97); 20 Jan 2003 16:07:43 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 15130 invoked by uid 97); 20 Jan 2003 16:07:43 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 15118 invoked by uid 98); 20 Jan 2003 16:07:42 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <3E2C1E72.8070103@joedog.org> Date: Mon, 20 Jan 2003 11:06:10 -0500 From: Tim Funk Organization: Human being User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Developers List Subject: Re: [general] Performance testing oddity References: <6333916.1043077535123.JavaMail.root@127.0.0.1> In-Reply-To: <6333916.1043077535123.JavaMail.root@127.0.0.1> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Could the compiler being doing some optimization? Version 1: The compiler might be able to infer that a HashMap is being used so it doesn't need a late-binding lookup on Map. Version 2: The late-binding lookup is needed since a Map is passed into the method. What happens if test(Map map) changes to test(HashMap map) for your test? -Tim scolebourne@btopenworld.com wrote: >> from: "Shapira, Yoav" >> >>>Test class #2) >>>public static void main(String[] args) { >>> Map map = new HashMap(); >>> map.put("AAA"); >>> map.put("BBB"); >>> map.put("CCC"); >>> >>> test(map); >>>} >>>private static void test(Map map) { >>> long start = 0; >>> long end = 0; >>> >>> start = System.currentTimeMillis(); >>> for (int i = RUNS; i >= 0; i--) { >>> map.get("AAA"); >>> map.get("BBB"); >>> map.get("CCC"); >>> } >>> end = System.currentTimeMillis(); >>> System.out.println(end - start); >>>} >>> >>>These two classes give very different results. The refactored version >> >>#2 is >> >>>much slower, between 20% and 80% depending on the type of Map. >>> >>>Am I missing something obvious??? >>>[Sun JDK 1.4.1_01 (client or server)] >> >>I don't think you're missing something obvious. But out of curiosity, >>if you mark the test(Map) method final, does the performance come out >>equal to version #1 of your class? It should, as the 1.4.1 compiler >>will inline the method. >> >>Also, does the 20% difference reduce when you increase RUNS? If RUNS is >>a very small value, then the method invocation overhead can actually be >>pretty high when compared to the run itself. Make RUNS 100000 and >>measure the difference between the classes again, if you haven't done so >>already... > > > The value I'm using for RUNS is 10,000,000, giving total time of the order of 2-7 seconds for each loop. > > Also, if you look at the code, the measurement (start to end) is all within the test(Map) method and doesn't include method invocations. Thats whats so strange... > > Stephen > -- To unsubscribe, e-mail: For additional commands, e-mail: