Re: Slow switch?
From: miguel sofer (msofer_at_users.sf.net)
Date: 10/16/03
- Next message: Aric Bills: "Re: Creating arrays out of thin air"
- Previous message: Bryan Oakley: "Re: Exec Hell - leftover sequel"
- In reply to: Luciano ES: "Slow switch?"
- Next in thread: Michael Schlenker: "Re: Slow switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 15 Oct 2003 19:29:21 -0300
Luciano ES wrote:
> I made a script:
>
> if { this } {that }
> if { this } {that }
> if { this } {that }
> if { this } {that }
> ...
>
> After a couple of days, I looked at the code again, felt ridiculous and
> replaced the whole series with a switch statement. Suddenly, the script
> became slower. It is very short so I can't really say it takes longer to
> do its job once it is launched, but it does seem to take longer to launch.
>
> Logic tells me I am crazy, but I kept the two scripts, ran them several
> times and still think the one with 'switch' takes longer *to launch*
> then the one with lots of IFs. Is there an unquestionable way to measure
> how long an app takes to launch?
>
> Thank you.
>
Don't trust logic in performance matters ;)
It may indeed be quite slower, on at least one of two counts:
(a) switch always compares as strings; this may be slower if your
conditions are numerical comparisons, depending on other details
(b) if this is inside the body of a proc (which should be true if you
are worried about performance), [if] is much faster as it is
bytecompiled, while [switch] isn't ([switch] is now bcc'ed in HEAD,
soon-to-be tcl8.5a1)
Until that comes around, the fastest is to use
if {...} {
....
} elseif {...} {
....
}
If the code runs more than once or accesses the same variable
repeatedly, put it within a proc body for extra gains.
Miguel
- Next message: Aric Bills: "Re: Creating arrays out of thin air"
- Previous message: Bryan Oakley: "Re: Exec Hell - leftover sequel"
- In reply to: Luciano ES: "Slow switch?"
- Next in thread: Michael Schlenker: "Re: Slow switch?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|