Mmmmm... I think it's the slower one... :(

-------------------------------------------------------------
| Executing performance test in Case Insensitive Maps       |
-------------------------------------------------------------
-------------------------------------------------------------
Run: 1/3
        Time (ms): 2360: MapTester$UpperCaseMap
        Time (ms): 1453: MapTester$TreeMapUpperCaseMap
        Time (ms): 907: MapTester$IgnoreCaseIntegerMap
        Time (ms): 844: MapTester$IgnoreCaseBitMap
        Time (ms): 7828: MapTester$ShiftBitMap
-------------------------------------------------------------
-------------------------------------------------------------
Run: 2/3
        Time (ms): 2235: MapTester$UpperCaseMap
        Time (ms): 1390: MapTester$TreeMapUpperCaseMap
        Time (ms): 844: MapTester$IgnoreCaseIntegerMap
        Time (ms): 750: MapTester$IgnoreCaseBitMap
        Time (ms): 7672: MapTester$ShiftBitMap
-------------------------------------------------------------
-------------------------------------------------------------
Run: 3/3
        Time (ms): 2281: MapTester$UpperCaseMap
        Time (ms): 1391: MapTester$TreeMapUpperCaseMap
        Time (ms): 765: MapTester$IgnoreCaseIntegerMap
        Time (ms): 766: MapTester$IgnoreCaseBitMap
        Time (ms): 7703: MapTester$ShiftBitMap
-------------------------------------------------------------

But have in mind that IgnoreCaseIntegerMap and IgnoreCaseBitMap creates
Integer objects that are more efficient that String, and may this not be
good for most cases when you need your keys in a human-readible fashion.
Creating Integer with this last shift left method still is less
efficient than AND aproach.

BTW, my PC is Compaq Pentium IV 2.4GHz and 1GB RAM, with WinXP, Eclipse
2.1 and JDK1.4

Saludos.
Guillermo


-----Original Message-----
From: Navjot Singh [mailto:[EMAIL PROTECTED] 
Sent: Martes, 17 de Febrero de 2004 04:17 a.m.
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: RE: [OT] Case insensitive Map keys [Results]


hi meyer,

Kudos to you for such a test.

Can you try this one for me. I could have tested here but would prefer
to run on the same configuration that you ran old test on. i didn't
check for syntax errors :)

private static class ShiftBitMap extends HashMap
{
        public Object put(Object key, Object value)
        {
                return
super.put(this.generateKey(key.toString()),value);
        }

        public Object get(Object key)
        {
                return super.get(this.generateKey(key.toString()));
        }

        private Object generateKey(String str)
        {
                byte[] bytes = str.getBytes();
                int len = bytes.length();

                for (int i=0; i<len; i++) bytes[i] <<= 3;
                return new String(bytes);
        }
}

>-----Original Message-----
>From: Guillermo Meyer [mailto:[EMAIL PROTECTED]
>Sent: Saturday, February 14, 2004 8:16 PM
>To: 'Struts Users Mailing List'
>Subject: RE: [OT] Case insensitive Map keys [Results]
>
>
>Navjot is the winner by now, this the code I'm using to test and the 
>results. Thanks for your responses.
>
>Guillermo.
>
>-------------------------------------------------------------
>| Executing performance test in Case Insensitive Maps       |
>-------------------------------------------------------------
>-------------------------------------------------------------
>Run: 1/3
>       Time (ms): 2312: MapTester$UpperCaseMap
>       Time (ms): 1469: MapTester$TreeMapUpperCaseMap
>       Time (ms): 812: MapTester$IgnoreCaseIntegerMap
>       Time (ms): 766: MapTester$IgnoreCaseBitMap
>-------------------------------------------------------------
>-------------------------------------------------------------
>Run: 2/3
>       Time (ms): 2234: MapTester$UpperCaseMap
>       Time (ms): 1391: MapTester$TreeMapUpperCaseMap
>       Time (ms): 766: MapTester$IgnoreCaseIntegerMap
>       Time (ms): 750: MapTester$IgnoreCaseBitMap
>-------------------------------------------------------------
>-------------------------------------------------------------
>Run: 3/3
>       Time (ms): 2203: MapTester$UpperCaseMap
>       Time (ms): 1390: MapTester$TreeMapUpperCaseMap
>       Time (ms): 813: MapTester$IgnoreCaseIntegerMap
>       Time (ms): 797: MapTester$IgnoreCaseBitMap
>-------------------------------------------------------------
>
>And this is the code:
>
>import java.util.HashMap;
>import java.util.Map;
>import java.util.TreeMap;
>
>public class MapTester {
>       final long running = 200000;
>
>       MapTester() {
>
>System.out.println("---------------------------------------------------
>-
>---------");
>               System.out.println("| Executing performance test in Case
>Insensitive Maps       |");
>
>System.out.println("---------------------------------------------------
>-
>---------");
>       }
>
>       private void runTest(Map mapa) {
>               long init = System.currentTimeMillis();
>               for(int i=0;i<running;i++) {
>                       mapa.put("propertyName1", new Integer(i+1));
>                       mapa.put("propertyName2", new Integer(i+2));
>                       mapa.put("propertyName3", new Integer(i+3));
>                       mapa.put("propertyName4", new Integer(i+4));
>                       mapa.put("propertyName5", new Integer(i+5));
>
>               }
>
>               for(int i=0;i<running;i++) {
>                       mapa.get("PropertyName1");
>                       mapa.get("PropertyName2");
>                       mapa.get("PropertyName3");
>                       mapa.get("PropertyName4");
>                       mapa.get("PropertyName5");
>               }
>
>               long end = System.currentTimeMillis();
>               System.out.println("\tTime (ms): " + (end - init) + ": "
>+ mapa.getClass().getName());
>       }
>
>
>       public static void main(String[] args) {
>               int cantCorridas=3;
>               MapTester mt = new MapTester();
>               for(int i=0;i<cantCorridas;i++) {
>
>System.out.println("---------------------------------------------------
>-
>---------");
>                       System.out.println("Run: " + (i+1) + "/" +
>cantCorridas);
>
>                       mt.runTest(new UpperCaseMap());
>
>                       mt.runTest(new TreeMapUpperCaseMap());
>
>                       mt.runTest(new IgnoreCaseIntegerMap());
>
>                       mt.runTest(new IgnoreCaseBitMap());
>
>System.out.println("---------------------------------------------------
>-
>---------");
>               }
>       }
>
>       private static  class UpperCaseMap extends HashMap {
>               public Object put(Object key, Object value) {
>                       return super.put(key.toString().toUpperCase(),
>value);
>               }
>
>               public Object get(Object key) {
>                       return
>super.get((key.toString()).toUpperCase());
>               }
>       }
>
>       private  static class TreeMapUpperCaseMap extends TreeMap {
>               public TreeMapUpperCaseMap() {
>                       super(String.CASE_INSENSITIVE_ORDER);
>               }
>       }
>
>       private static class IgnoreCaseIntegerMap extends HashMap {
>               public Object put(Object key, Object value) {
>                       return
>super.put(this.generateKey(key.toString()), value);
>               }
>
>               public Object get(Object key) {
>                       return
>super.get(this.generateKey(key.toString()));
>               }
>
>               private Object generateKey(String str) {
>
>                       int len = str.length();
>                       int h=0;
>                       char val[] = str.toCharArray();
>                       char c;
>                       for (int i = 0; i < len; i++) {
>                               c=val[i++];
>                               if(c>=97 && c <=122)
>                                       c-=32;
>
>                               h = 31*h + c;
>                       }
>                       return new Integer(h);
>               }
>       }
>
>       private static class IgnoreCaseBitMap extends HashMap {
>               public Object put(Object key, Object value) {
>                       return
>super.put(this.generateKey(key.toString()), value);
>               }
>
>               public Object get(Object key) {
>                       return
>super.get(this.generateKey(key.toString()));
>               }
>
>               private Object generateKey(String str) {
>                       int len = str.length();
>                       int h=0;
>                       char val[] = str.toCharArray();
>                       for (int i = 0; i < len; i++) {
>                               h = 31*h + (val[i++]&223);
>                       }
>                       return new Integer(h);
>               }
>       }
>
>}
>
>
>-----Original Message-----
>From: Navjot Singh [mailto:[EMAIL PROTECTED]
>Sent: Sábado, 14 de Febrero de 2004 03:16 a.m.
>To: Struts Users Mailing List; [EMAIL PROTECTED]
>Subject: RE: [OT] Case insensitive Map keys
>
>
>hi,
>
>seems like you are ready to go down to bits. my 2 cents for you to try
>
>==> convert string to array of bytes.
>
>1. AND every byte with 11011111. all will give you same output. OR 2. 
>shift left the every byte by 3 bits.
>
>keep pushing the resulting byte to another array.
>create string again of those bytes.
>
>Saves you 2 relations operator, one condiiton checking, one 
>subtraction-assign. object creation is same. you create Integer. I 
>create String.
>
>please let us know if you gain some performance.
>
>
>>-----Original Message-----
>>From: Guillermo Meyer [mailto:[EMAIL PROTECTED]
>>Sent: Friday, February 13, 2004 7:08 PM
>>To: 'Struts Users Mailing List'
>>Subject: RE: [OT] Case insensitive Map keys
>>
>>
>>I'm trying the following:
>>
>>      public class KeyGeneratedMap extends HashMap {
>>              public Object put(Object key, Object value) {
>>                      return
>>super.put(this.generateKey(key.toString()), value);
>>              }
>>
>>              public Object get(Object key) {
>>                      return
>>super.get(this.generateKey(key.toString()));
>>              }
>>
>>              /**
>>              * This generates an integer object for Strings and are
>>case insensitive, that is
>>              * Hello and heLLO generate the same Integer object value
>>              */
>>              private Object generateKey(String str) {
>>                      int len = str.length();
>>                      int h=0;
>>                      char val[] = str.toCharArray();
>>                      char c;
>>                      for (int i = 0; i < len; i++) {
>>                              c=val[i++];
>>                              if(c>=97 && c <=122)
>>                                      c-=32;
>>
>>                              h = 31*h + c;
>>                      }
>>                      return new Integer(h);
>>              }
>>      }
>>
>>This by now is three times faster than using toUpperCase for storing 
>>and retrievinig items from the hash. What do you think?
>>
>>-----Original Message-----
>>From: Navjot Singh [mailto:[EMAIL PROTECTED]
>>Sent: Viernes, 13 de Febrero de 2004 02:53 a.m.
>>To: Struts Users Mailing List
>>Subject: RE: [OT] Case insensitive Map keys
>>
>>
>>oops!! thanks for correcting me freddy.
>>
>>well in that case, if you map is not modified frequently, try the 
>>FastHashMap from the Apache Commons. either you override and read and 
>>write your own.
>>
>>>-----Original Message-----
>>>From: Villalba Arias, Fredy [BILBOMATICA] 
>>>[mailto:[EMAIL PROTECTED]
>>>Sent: Thursday, February 12, 2004 5:50 PM
>>>To: Struts Users Mailing List
>>>Subject: RE: [OT] Case insensitive Map keys
>>>
>>>
>>>Navjot,
>>>
>>>I believe this is exactly what Guillermo CLEARLY stated he had 
>>>already
>
>>>tried (and is not efficient enough for him).
>>>
>>>If you had taken a little bit longer and read carefully, then maybe 
>>>you'd have noticed.
>>>
>>>Regards,
>>>Freddy.
>>>
>>>-----Mensaje original-----
>>>De: Navjot Singh [mailto:[EMAIL PROTECTED]
>>>Enviado el: jueves, 12 de febrero de 2004 13:14
>>>Para: Struts Users Mailing List; [EMAIL PROTECTED]
>>>Asunto: RE: [OT] Case insensitive Map keys
>>>
>>>yes. here it is.
>>>
>>>public CIMap extends HashMap
>>>{
>>>
>>>     public Object get(String key)
>>>     {
>>>             return super.get(key.toLowerCase());
>>>     }
>>>
>>>     public Object put(String key, Object value)
>>>     {
>>>             super.put(key.toLowerCase(),value);
>>>     }
>>>}
>>>
>>>This was simple implementation. By the time you ask the Q and wait 
>>>for
>
>>>reply. you could have written on your own.
>>>
>>>Navjot Singh
>>>
>>>
>>>>-----Original Message-----
>>>>From: Guillermo Meyer [mailto:[EMAIL PROTECTED]
>>>>Sent: Thursday, February 12, 2004 5:24 PM
>>>>To: 'Struts Users Mailing List'
>>>>Subject: [OT] Case insensitive Map keys
>>>>
>>>>
>>>>Hi:
>>>>Does anyone know an implementation of Map where keys are String and 
>>>>case insensitive? I want to do this:
>>>>
>>>>map.put("propertyName", "DATA");
>>>>
>>>>And then, I should be able to get the value like this: Object obj = 
>>>>map.get("PROPERTYNAME");
>>>>
>>>>Or like this:
>>>>Object obj = map.get("propertyname"); //or whatever. case 
>>>>insensitive.
>>>>
>>>>We tried using toUppercase when putting and toUppercase when 
>>>>getting,
>
>>>>and using equalsIgnoreCase but this is not as efficient as we need. 
>>>>May there be a way to calculate a hash for strings in upper or lower

>>>>case to result in the same value?
>>>>
>>>>Thanks in advance.
>>>>
>>>>Guillermo.
>>>>
>>>>
>>>>NOTA DE CONFIDENCIALIDAD
>>>>Este mensaje (y sus anexos) es confidencial, esta dirigido 
>>>>exclusivamente a las personas direccionadas en el mail y puede 
>>>>contener informacion (i)de propiedad exclusiva de Interbanking S.A. 
>>>>o
>>>>(ii) amparada por el secreto profesional. Cualquier opinion en el
>>>>contenido, es exclusiva de su autor y no representa necesariamente
la
>
>>>>opinion de Interbanking S.A. El acceso no autorizado, uso, 
>>>>reproduccion, o divulgacion esta prohibido. Interbanking S.A no 
>>>>asumira responsabilidad ni obligacion legal alguna por cualquier 
>>>>informacion incorrecta o alterada contenida en este mensaje. Si 
>>>>usted
>
>>>>ha recibido este mensaje por error, le rogamos tenga la amabilidad 
>>>>de
>
>>>>destruirlo inmediatamente junto con todas las copias del mismo, 
>>>>notificando al remitente. No debera utilizar, revelar, distribuir, 
>>>>imprimir o copiar este mensaje ni ninguna de sus partes si usted no 
>>>>es
>>
>>>>el destinatario. Muchas gracias.
>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>---
>>>Incoming mail is certified Virus Free.
>>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>>Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003
>>>
>>>
>>>---
>>>Outgoing mail is certified Virus Free.
>>>Checked by AVG anti-virus system (http://www.grisoft.com).
>>>Version: 6.0.459 / Virus Database: 258 - Release Date: 25/02/2003
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>NOTA DE CONFIDENCIALIDAD
>>Este mensaje (y sus anexos) es confidencial, esta dirigido 
>>exclusivamente a las personas direccionadas en el mail y puede 
>>contener
>
>>informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) 
>>amparada por el secreto profesional. Cualquier opinion en el 
>>contenido,
>
>>es exclusiva de su autor y no representa necesariamente la opinion de 
>>Interbanking S.A. El acceso no autorizado, uso, reproduccion, o 
>>divulgacion esta prohibido. Interbanking S.A no asumira 
>>responsabilidad
>
>>ni obligacion legal alguna por cualquier informacion incorrecta o 
>>alterada contenida en este mensaje. Si usted ha recibido este mensaje 
>>por error, le rogamos tenga la amabilidad de destruirlo inmediatamente

>>junto con todas las copias del mismo, notificando al remitente. No 
>>debera utilizar, revelar, distribuir, imprimir o copiar este mensaje 
>>ni ninguna de sus partes si usted no es el destinatario. Muchas 
>>gracias.
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>NOTA DE CONFIDENCIALIDAD
>Este mensaje (y sus anexos) es confidencial, esta dirigido 
>exclusivamente a las personas direccionadas en el mail y puede contener

>informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) 
>amparada por el secreto profesional. Cualquier opinion en el contenido,

>es exclusiva de su autor y no representa necesariamente la opinion de 
>Interbanking S.A. El acceso no autorizado, uso, reproduccion, o 
>divulgacion esta prohibido. Interbanking S.A no asumira responsabilidad

>ni obligacion legal alguna por cualquier informacion incorrecta o 
>alterada contenida en este mensaje. Si usted ha recibido este mensaje 
>por error, le rogamos tenga la amabilidad de destruirlo inmediatamente 
>junto con todas las copias del mismo, notificando al remitente. No 
>debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni
>ninguna de sus partes si usted no es el destinatario. Muchas gracias.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>

NOTA DE CONFIDENCIALIDAD
Este mensaje (y sus anexos) es confidencial, esta dirigido exclusivamente a las 
personas direccionadas en el mail y puede contener informacion (i)de propiedad 
exclusiva de Interbanking S.A. o (ii) amparada por el secreto profesional. Cualquier 
opinion en el contenido, es exclusiva de su autor y no representa necesariamente la 
opinion de Interbanking S.A. El acceso no autorizado, uso, reproduccion, o divulgacion 
esta prohibido. Interbanking S.A no asumira responsabilidad ni obligacion legal alguna 
por cualquier informacion incorrecta o alterada contenida en este mensaje. Si usted ha 
recibido este mensaje por error, le rogamos tenga la amabilidad de destruirlo 
inmediatamente junto con todas las copias del mismo, notificando al remitente. No 
debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni ninguna de sus 
partes si usted no es el destinatario. Muchas gracias.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to