Return-Path: Delivered-To: apmail-wicket-dev-archive@www.apache.org Received: (qmail 41839 invoked from network); 13 Feb 2009 16:58:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Feb 2009 16:58:53 -0000 Received: (qmail 99574 invoked by uid 500); 13 Feb 2009 16:58:52 -0000 Delivered-To: apmail-wicket-dev-archive@wicket.apache.org Received: (qmail 99553 invoked by uid 500); 13 Feb 2009 16:58:51 -0000 Mailing-List: contact dev-help@wicket.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@wicket.apache.org Delivered-To: mailing list dev@wicket.apache.org Received: (qmail 99542 invoked by uid 99); 13 Feb 2009 16:58:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2009 08:58:51 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of igor.vaynberg@gmail.com designates 209.85.220.19 as permitted sender) Received: from [209.85.220.19] (HELO mail-fx0-f19.google.com) (209.85.220.19) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Feb 2009 16:58:43 +0000 Received: by fxm12 with SMTP id 12so2235810fxm.8 for ; Fri, 13 Feb 2009 08:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=iXpEWKKukofZEQrjozpCzKPbjGR0nxQI3pILzJmnPjw=; b=DOTs+g3kAHwLYN9pz0x4nl0BDefG69gwXteuaEaw9ytJmj07Ylg0lhq4IdxkOZqahA mOIs+L0HtOc+mea8MupMbspIitfI92+zNEm1pXrH89Sv7qvcqAxHG36HSHAWEoQzbVQT CblSgaJTFJBT5t2jS04JZKZSZYSbRmfXH9o78= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=f6AZltMe0mzRqB7Mt2UGVtctaFNSTThsP2/f5mFNWeJmSmjKkT8HmaKEb/AvZ32uIX SN5XXqqgYcsvtn8Fz5Ws2f/BDgbB0iABZj5D6GahzgrFy59o5LNJ/DP863+gluLqXwEq Izcqqka7d87YxrsQS1KwwetNO6sUxSGhTkm1k= MIME-Version: 1.0 Received: by 10.103.49.12 with SMTP id b12mr1365145muk.81.1234544077556; Fri, 13 Feb 2009 08:54:37 -0800 (PST) In-Reply-To: <4995329F.2050007@ri.fi> References: <20090212234017.5hfam7nysso8kwsw@webmail.ri.fi> <23eb48360902121413yc60f69dj692d78b6f80653a7@mail.gmail.com> <4995329F.2050007@ri.fi> Date: Fri, 13 Feb 2009 08:54:37 -0800 Message-ID: <23eb48360902130854n702a8236odaff86ebdcaf9c0b@mail.gmail.com> Subject: Re: IntHashMap From: Igor Vaynberg To: dev@wicket.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org considering with diskstore there is only one page in a pagemap... -igor On Fri, Feb 13, 2009 at 12:43 AM, Tuomas K=E4rkk=E4inen wrote: > Hi, > > I couldn't gather from the javadoc when IntHashMap should be preferred ov= er > a regular HashMap, i.e. how many objects per map, what type of objects et= c. > > I wrote a little program (copy pasted at the bottom) to see how much the > size difference was for IntHashMap, java.util.HashMap and > java.util.concurrent.ConcurrentHashMap. > > for 1 instance of new org.apache.wicket.Page(){}; > for 10 instances of new org.apache.wicket.Page(){}; > for 100 instances of new > org.apache.wicket.ajax.form.AjaxFormSubmitTestPage(); > > Br, > Tuomas > > the results are as follows, respectively: > > -------------------------------------------------- > > map implementation: org.apache.wicket.util.collections.IntHashMap -- size= of > outputstream: 54 bytes. > map implementation: java.util.HashMap -- size of outputstream: 57 bytes. > map implementation: java.util.concurrent.ConcurrentHashMap -- size of > outputstream: 282 bytes. > HashMap is 5.556% larger than IntHashMap. > ConcurrentHashMap is 422.222% larger than IntHashMap. > > -- > > map implementation: org.apache.wicket.util.collections.IntHashMap -- size= of > outputstream: 369 bytes. > map implementation: java.util.HashMap -- size of outputstream: 399 bytes. > map implementation: java.util.concurrent.ConcurrentHashMap -- size of > outputstream: 624 bytes. > HashMap is 8.130% larger than IntHashMap. > ConcurrentHashMap is 69.106% larger than IntHashMap. > > -- > > map implementation: org.apache.wicket.util.collections.IntHashMap -- size= of > outputstream: 24272 bytes. > map implementation: java.util.HashMap -- size of outputstream: 24572 byte= s. > map implementation: java.util.concurrent.ConcurrentHashMap -- size of > outputstream: 24797 bytes. > HashMap is 1.236% larger than IntHashMap. > ConcurrentHashMap is 2.163% larger than IntHashMap. > > > ---------- > > /* > * Licensed to the Apache Software Foundation (ASF) under one or more > * contributor license agreements. See the NOTICE file distributed with > * this work for additional information regarding copyright ownership. > * The ASF licenses this file to You under the Apache License, Version 2.= 0 > * (the "License"); you may not use this file except in compliance with > * the License. You may obtain a copy of the License at > * > * http://www.apache.org/licenses/LICENSE-2.0 > * > * Unless required by applicable law or agreed to in writing, software > * distributed under the License is distributed on an "AS IS" BASIS, > * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implie= d. > * See the License for the specific language governing permissions and > * limitations under the License. > */ > package org.apache.wicket.util.collections; > > > import java.io.IOException; > import java.util.HashMap; > import java.util.concurrent.ConcurrentHashMap; > > import org.apache.wicket.Page; > import org.apache.wicket.util.io.ByteArrayOutputStream; > import org.apache.wicket.util.io.WicketObjectOutputStream; > import org.apache.wicket.util.tester.WicketTester; > > public class Tester > { > private static final int NUMBER_OF_PAGES =3D 1; > > > public static void main(String[] args) throws Exception > { > int intHashMapSize =3D writeMap(populatedIntHashMap()); > int hashMapSize =3D writeMap(populatedHashMap()); > int concurrentHashMapSize =3D > writeMap(populatedConcurrentHashMap()); > double hashMapIsLargerPercetange =3D > ((Double.valueOf(hashMapSize) / intHashMapSize) - 1) * 100; > double concurrentHashMapIsLargerPercetange =3D > ((Double.valueOf(concurrentHashMapSize) / intHashMapSize) - 1) * 100; > System.out.printf("HashMap is %.3f%% larger than > IntHashMap.%n", hashMapIsLargerPercetange); > System.out.printf("ConcurrentHashMap is %.3f%% larger than > IntHashMap.%n", > concurrentHashMapIsLargerPercetange); > } > > private static int writeMap(Object map) throws IOException > { > ByteArrayOutputStream out =3D new ByteArrayOutputStream(); > WicketObjectOutputStream objectOutputStream =3D new > WicketObjectOutputStream(out); > objectOutputStream.writeObject(map); > System.out.printf("map implementation: %s -- size of > outputstream: %d bytes.%n", > map.getClass().getName(), out.size()); > return out.size(); > } > > private static HashMap populatedHashMap() > { > new WicketTester(); > HashMap map =3D new HashMap(= ); > for (int i =3D 0; i < NUMBER_OF_PAGES; i++) > { > map.put(i, createPage()); > } > return map; > } > > private static ConcurrentHashMap > populatedConcurrentHashMap() > { > new WicketTester(); > ConcurrentHashMap map =3D new > ConcurrentHashMap(); > for (int i =3D 0; i < NUMBER_OF_PAGES; i++) > { > map.put(i, createPage()); > } > return map; > } > > > private static IntHashMap populatedIntHashMap() > { > new WicketTester(); > IntHashMap map =3D new IntHashMap(); > for (int i =3D 0; i < NUMBER_OF_PAGES; i++) > { > map.put(i, createPage()); > } > return map; > } > > > private static Page createPage() > { > Page page =3D new Page() > { > }; > page.detach(); > return page; > } > } > > > Igor Vaynberg wrote: >> >> exactly what the javadoc says, its a map that does not need to store a >> key object. so it is smaller than a regular hashmap when serialized or >> kept in memory. >> >> -igor >> >> On Thu, Feb 12, 2009 at 1:40 PM, Tuomas K=E4rkk=E4inen >> wrote: >>> >>> Hi, >>> >>> I was looking at IntHashMap in wicket trunk. >>> >>> I couldn't figure out what it does. >>> >>> The implementation of hashcode for Integer is value, and the autoboxing >>> of >>> int to Integer comes out to Integer.valueOf(int) which is implemented a= s >>> an >>> array lookup for Integers in the range of -128 to 127, and beyond that >>> it's >>> just new Integer(int). Page ids start at zero for each page in each >>> session >>> so most of the time they will be between zero and 127. >>> >>> Br, >>> Tuomas >>> >>> > >