I have no idea if my test is ok, but I've got string being 3 1/2 times slower than
switch.. thats not taking into account the cost
of figuring out an int value for the stirng of course.
test:
public class EqualsVsSwitch
{
public static final int FOO_AS_INT = 0;
public static final int BAR_AS_INT = 1;
public static final int ABC_AS_INT = 2;
public static final int DEF_AS_INT = 3;
public static final String FOO = "foo";
public static final String BAR = "bar";
public static final String ABC = "abc";
public static final String DEF = "def";
public static final String[] strings = new String[] { FOO, BAR, ABC, DEF };
long testEquals(int repeat)
{
long start = System.currentTimeMillis();
int idx = 0;
for (int i=0; i<repeat; i++)
{
String var = strings[idx];
if (var.equals(FOO))
{
}
else if (var.equals(BAR))
{
}
else if (var.equals(ABC))
{
}
else if (var.equals(DEF))
{
}
if (++idx > 3) idx = 0;
}
long end = System.currentTimeMillis();
return end - start;
}
long testSwitch(int repeat)
{
long start = System.currentTimeMillis();
int idx = 0;
for (int i=0; i<repeat; i++)
{
// here to ensure the same stuff gets done
// - does the compiler take it out tho?
String var = strings[idx];
switch (idx)
{
case FOO_AS_INT:
break;
case BAR_AS_INT:
break;
case ABC_AS_INT:
break;
case DEF_AS_INT:
break;
}
if (++idx > 3) idx = 0;
}
long end = System.currentTimeMillis();
return end - start;
}
public static final int LOOPS = 500000;
public static void main(String[] args)
{
EqualsVsSwitch test = new EqualsVsSwitch();
long totalEqual = test.testEquals(LOOPS);
long totalSwitch = test.testSwitch(LOOPS);
System.out.println("Equal: " + totalEqual);
System.out.println("Switch: " + totalSwitch);
}
}
and results:
Equal: 70
Switch: 10
cheesr
dim
----- Original Message -----
From: "marc fleury" <[EMAIL PROTECTED]>
To: "marc fleury" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Thursday, February 07, 2002 8:05 PM
Subject: RE: RE: RE: [JBoss-dev] something is broken...
> Ok webinf done, my eyes are tired
>
> I will look briefly at the EC fix for switch instead of Sring
> manipulation...
>
> anyone knows the time it takes for either one?
>
> marcf
>
> |-----Original Message-----
> |From: [EMAIL PROTECTED]
> |[mailto:[EMAIL PROTECTED]]On Behalf Of marc
> |fleury
> |Sent: Wednesday, February 06, 2002 11:50 PM
> |To: [EMAIL PROTECTED]
> |Subject: RE: RE: RE: [JBoss-dev] something is broken...
> |
> |
> |following our little conversation with Jason, I understand the problem and
> |it is indeed me, i forgot to adapt the new entitycontainer to the new "int"
> |based switch as opposed to string manipulation.
> |
> |will fix in the coming hours, fuck I need to fly tomorrow....
> |
> |Also I am almost done with the webinf/classes fix.
> |
> |and then bill and scott get to breeze and roam free, I am gone for
> |a fucking
> |10 days and you guys get to not have me break cvs every hours or so...
> |
> |Here is a promise, if you guys bring the errors to zero I promise to ALWAYS
> |run the testsuite everytime I commit a line of comment, that will be my
> |penitence.
> |
> |maybe
> |
> ||-----Original Message-----
> ||From: [EMAIL PROTECTED]
> ||[mailto:[EMAIL PROTECTED]]On Behalf Of Jason
> ||Dillon
> ||Sent: Wednesday, February 06, 2002 8:21 PM
> ||To: [EMAIL PROTECTED]
> ||Subject: Re: RE: RE: [JBoss-dev] something is broken...
> ||
> ||
> ||What is the operation that invoke is supposed to call? I guess
> ||there is just one now... looking it up from cvslogs (but if you
> ||could tell me it would be easier).
> ||
> ||--jason
> ||
> ||_________________________________________________________
> ||View thread online: http://main.jboss.org/thread.jsp?forum=66&thread=7990
> ||
> ||_______________________________________________
> ||Jboss-development mailing list
> ||[EMAIL PROTECTED]
> ||https://lists.sourceforge.net/lists/listinfo/jboss-development
> |
> |
> |_______________________________________________
> |Jboss-development mailing list
> |[EMAIL PROTECTED]
> |https://lists.sourceforge.net/lists/listinfo/jboss-development
>
>
> _______________________________________________
> Jboss-development mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-development
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development