Re: [WebDNA] SWITCH/CASE or SHOWIF

This WebDNA talk-list message is from

2008


It keeps the original formatting.
numero = 101492
interpreted = N
texte = FWIW, I tested both sets of code below and saw absolutely ZERO difference= in performance. -Dan On Thu, 20 Nov 2008 12:44:21 -0800 "Dan Strong" wrote: > On Thu, 20 Nov 2008 14:53:13 -0500 > Ki Song wrote: >> We have about a 100 different brands at our store. >> Some brands have "static" brand pages (brand/index.html) while others = have "dynamic" brand pages=20 >>(dynamic.tpl?brand=3Dsomebrand). >>=20 >> 1. To go through 100 different choices, is a switch/case more efficien= t or 100 showif statements=20 >>more efficient? >=20 > My instict is that switch/case would be faster since it seems to be a "= single" operation vs 100=20 >[showif] operations, but it is untested and based on nothing but my own = buest guess. >=20 > Try a test similar to these and wrap [elapsedtime] around them or compa= re the start [time] to=20 >the end [time]: >=20 > [text]x=3D[math]ceil([RANDOM format=3Dfloat]*(100))[/math][/text] >=20 > [Switch value=3D[x]] > [loop start=3D1&end=3D100] > [Case value=3D[index]]The value of x is [x][/Case] > [/loop] > [Default] > [!]--The "default" case is probably not needed here since one of = these cases will *always*=20 > be true, but hey, I still end my [search]es w/ [/search] --[/!] > [/Default] > [/Switch] >=20 > ------------ >=20 > [text]x=3D[math]ceil([RANDOM format=3Dfloat]*(100))[/math][/text] >=20 > [loop start=3D1&end=3D100] > [showif [x]=3D[index]]The value of x is [x][/showif] > [/loop] >=20 > I'd be curious to see what the results are. >=20 >> 2. In the final generated HTML code, when 100 SHOWIF statements are pr= ocessed, but only 1 is=20 >>actually shown, the other 99 SHOWIF statements create line breaks. Is t= here a way to prevent the=20 >>line breaks from showing up if a showif does not evaluate to true? >=20 > I got this one from someone on the list: >=20 > Wrap all "line-breaky" code like this: >=20 > [getchars start=3D1&end=3D&trim=3Dboth] > [grep search=3D[%0D%0A][%0D%0A%09]*&replace=3D%0D] > ... your line-breaky code goes here ... > [/grep] > [/getchars] >=20 >>=20 >> 3. Does a SWITCH/CASE statement create line breaks for all the cases t= hat evaluate to false? >=20 > Dunno, but if so, wrap like above. > -Dan Associated Messages, from the most recent to the oldest:

    
  1. Re: [WebDNA] SWITCH/CASE or SHOWIF (Ki Song 2008)
  2. Re: [WebDNA] SWITCH/CASE or SHOWIF ("Dan Strong" 2008)
  3. Re: [WebDNA] SWITCH/CASE or SHOWIF (Toby Cox 2008)
  4. Re: [WebDNA] SWITCH/CASE or SHOWIF (Govinda 2008)
  5. Re: [WebDNA] SWITCH/CASE or SHOWIF ("Dan Strong" 2008)
  6. Re: [WebDNA] SWITCH/CASE or SHOWIF (Ki Song 2008)
  7. Re: [WebDNA] SWITCH/CASE or SHOWIF (Govinda 2008)
  8. [WebDNA] SWITCH/CASE or SHOWIF (Ki Song 2008)
FWIW, I tested both sets of code below and saw absolutely ZERO difference= in performance. -Dan On Thu, 20 Nov 2008 12:44:21 -0800 "Dan Strong" wrote: > On Thu, 20 Nov 2008 14:53:13 -0500 > Ki Song wrote: >> We have about a 100 different brands at our store. >> Some brands have "static" brand pages (brand/index.html) while others = have "dynamic" brand pages=20 >>(dynamic.tpl?brand=3Dsomebrand). >>=20 >> 1. To go through 100 different choices, is a switch/case more efficien= t or 100 showif statements=20 >>more efficient? >=20 > My instict is that switch/case would be faster since it seems to be a "= single" operation vs 100=20 >[showif] operations, but it is untested and based on nothing but my own = buest guess. >=20 > Try a test similar to these and wrap [elapsedtime] around them or compa= re the start [time] to=20 >the end [time]: >=20 > [text]x=3D[math]ceil([RANDOM format=3Dfloat]*(100))[/math][/text] >=20 > [Switch value=3D[x]] > [loop start=3D1&end=3D100] > [Case value=3D[index]]The value of x is [x][/Case] > [/loop] > [Default] > [!]--The "default" case is probably not needed here since one of = these cases will *always*=20 > be true, but hey, I still end my [search]es w/ [/search] --[/!] > [/Default] > [/Switch] >=20 > ------------ >=20 > [text]x=3D[math]ceil([RANDOM format=3Dfloat]*(100))[/math][/text] >=20 > [loop start=3D1&end=3D100] > [showif [x]=3D[index]]The value of x is [x][/showif] > [/loop] >=20 > I'd be curious to see what the results are. >=20 >> 2. In the final generated HTML code, when 100 SHOWIF statements are pr= ocessed, but only 1 is=20 >>actually shown, the other 99 SHOWIF statements create line breaks. Is t= here a way to prevent the=20 >>line breaks from showing up if a showif does not evaluate to true? >=20 > I got this one from someone on the list: >=20 > Wrap all "line-breaky" code like this: >=20 > [getchars start=3D1&end=3D&trim=3Dboth] > [grep search=3D[%0D%0A][%0D%0A%09]*&replace=3D%0D] > ... your line-breaky code goes here ... > [/grep] > [/getchars] >=20 >>=20 >> 3. Does a SWITCH/CASE statement create line breaks for all the cases t= hat evaluate to false? >=20 > Dunno, but if so, wrap like above. > -Dan "Dan Strong"

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

installing webcatalog problem. HELP! (1998) Re:Virtual hosting and webcatNT (1997) Multiple Merchant Accounts? (1997) SOLUTION.... Balancing randomness (2000) Pithy questions on webcommerce & siteedit (1997) Generating Report Totals (1997) redirect within a showif (1998) writefiles (1999) [WebDNA] WebDNA Roll Call (2013) [addlineitems] display (1997) Re:Emailer tracking (1997) [WebDNA] remove html comments (2009) ThisAutoNumber (2003) Fileinfo... (2000) OT: test (1998) WebDNA 4.5.1 on Apache 2.x. (2004) $Replace with [founditems] (1997) RE: WebCat cannot handle compatible search parameters? (1997) Webmerchant (1999) Comments in db? (1997)