  | |  | AW: [Flashcoders] Switch/Case vs If/else | AW: [Flashcoders] Switch/Case vs If/else
2004-02-11 - By Mees, Stefan
Back <code >
switch(bla) {
case 1 : doSomeThing1(); break;
case 2 : doSomeThing2(); break;
default: doNothing();
}
</code >
is the same code bytecode than
<code >
if(bla === 1) {
doSomeThing1();
} else if (bla === 2) {
doSomeThing2();
} else {
doNothing();
}
</code >
the only difference is the first one looks nicer ;-)
-- --Ursprüngliche Nachricht-- --
Von: Ilja Goossens [mailto:ilja.goossens@(protected)]
Gesendet: Mittwoch, 11. Februar 2004 13:33
An: flashcoders@(protected)
Betreff: RE: [Flashcoders] Switch/Case vs If/else
sorry 'almighty ' keith...
:P
-- --Oorspronkelijk bericht-- --
Van: Keith Peters [mailto:flashcoder@(protected)]
Verzonden: woensdag 11 februari 2004 13:19
Aan: flashcoders@(protected)
Onderwerp: RE: [Flashcoders] Switch/Case vs If/else
Please don 't give ideas or opinions on how commands work. They either
work a certain way or they work another way.
If you KNOW how they work, please share. If you just THINK they work
that way, it 's not very helpful.
As for the original question, you can test the speed of any function
yourself.
startTime = getTimer();
for(var i=0;i <1000;i++){
// test a switch statement here
}
trace(getTimer() - startTime);
startTime = getTimer();
for(var i=0;i <1000;i++){
// test an equivalent if statement here
}
trace(getTimer() - startTime);
Run it several times to be sure.
Then you will KNOW.
> -- --Original Message-- --
> From: Ilja Goossens [mailto:ilja.goossens@(protected)]
> Sent: Wednesday, February 11, 2004 6:52 AM
> To: flashcoders@(protected)
> Subject: RE: [Flashcoders] Switch/Case vs If/else
>
>
> I think the difference is that every condition in the if/else
> gets evaluated And a switch knows wich case has to be
> performed, without evaluating them each time.
>
> So I think the switch will be faster as the amount of
> cases/elses increases
>
> -- --Oorspronkelijk bericht-- --
>
>
>
> i think to remember that switch/case is in byte code the same
> result than If/Else... the only difference is better looking
> source code.. Best, Stefan
>
>
>
> -- --Ursprüngliche Nachricht-- --
>
>
>
> Is switch/case faster than if/else?
>
> - Andreas SJ
>
>
>
>
>
>
> =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
> -- ------
> Supported by Fig Leaf Software
> =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
> -- ------
> Be sure to check the archives and the wiki:
> http://chattyfig.figleaf.com/
>
> =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
> -- ------
> http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:103775
> =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
> -- ------
> To unsubscribe send a blank e-mail to:
> Normal Mode: flashcoders-unsubscribe@(protected)
> Digest Mode: flashcoders-digest-unsubscrive@(protected)
>
>
>
>
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:103780
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:103781
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:103783
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |