[thelist] CF: Tag to insert into body tag

jeff jeff at members.evolt.org
Mon Mar 19 16:46:31 CST 2001


raymond,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Raymond Camden
:
: > before you rush off to build a cf_body
: > custom tag, let me warn against this
: > route in favor of the script block
: > method i proposed for performance reasons
: > related to custom tags.  you're much
: > better off avoiding the performance hit
: > of the custom tag by using a different
: > method of calling a function with the
:
: While I agree with the solution you provided,
: what do you mean by performance hit?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

well, it depends on how you call the custom tag -- without an end tag, with
an end tag, or as a module.  they each have their own set of peformance
issues.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Sure, more code equals more stuff to process
: equals more _time_ to process. Sure, a solution
: written in JavaScript will be faster, but you
: seem to be implying the custom tags in _general_
: are bad for performance. This is not the case.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

joshua (a co-worker) has already touched on our experiences here, but i
thought i'd do some very basic testing to see if i could generate some
numbers that would give a more solid indication of what i'm talking about.

i started by creating a loop from 1 to 10,000.  inside that loop i tried
several different things.  here's what i tried and the processing time (in
milliseconds) that resulted from 6 refreshes of each combination (throwing
out the first to account for the additional time to convert to pcode the
first time after a document change):


1.  no external file - <cfoutput) inside the loop

    -- index.cfm --

    <cfloop from="1" to="10000" index="i">
      <cfoutput>#i#<br></cfoutput>
    </cfloop>

    -- processing time --

    371
    361
    360
    371
    370


2.  no external file - <cfoutput> outside the loop
    (notice the slight performance gain)

    -- index.cfm --

    <cfoutput>
    <cfloop from="1" to="10000" index="i">
      #i#<br>
    </cfloop>
    </cfoutput>

    -- processing time --

    330
    340
    340
    340
    340


3.  calling a cfmodule and passing the
    value in via an attribute

    -- index.cfm --

    <cfloop from="1" to="10000" index="i">
      <cfmodule template="cfmodule_test.cfm" number="#i#">
    </cfloop>

    -- cfmodule_test.cfm --

    <cfparam name="attributes.number" default="0">

    <cfoutput>
    #attributes.number#<br>
    </cfoutput>

    -- processing time --

    10435
      module: 1933
      index:  1933
    10545
      module: 1792
      index:  8823
    10605
      module: 1851
      index:  8824
    10405
      module: 1933
      index:  1933
    10395
      module: 1892
      index:  8563

4.  calling a custom tag without an end tag
    and passing a value in via an attribute

    -- index.cfm --

    <cfloop from="1" to="10000" index="i">
      <cf_cfnoend_test number="#i#">
    </cfloop>

    -- cfnoend_test --

    <cfparam name="attributes.number" default="0">

    <cfoutput>
    #attributes.number#<br>
    </cfoutput>

    -- processing time --

    8963
      custom tag:  1572
      index:       7430
    9054
      custom tag:  1572
      index:       7562
    8953
      custom tag:  1603
      index:       7390
    8952
      custom tag:  1462
      index:       7500
    8943
      custom tag:  1693
      index:       7350


5.  calling a custom tag with an end tag and
    passing the value in between the start
    and end tag.

    -- index.cfm --

    <cfoutput>
    <cfloop from="1" to="10000" index="i">
      <cf_cfend_test>
        #i#
      </cf_cfend_test>
    </cfloop>
    </cfoutput>

    -- cfend_test.cfm --

    <cfif thisTag.ExecutionMode IS "End">
      <br>
    </cfif>

    -- processing time --

    13469
      custom tag:  3622
      index:       10017
    13860
      custom tag:  3277
      index:       10684
    13530
      custom tag:  3304
      index:       10266
    13520
      custom tag:  3244
      index:       10406
    13539
      custom tag:  3385
      index:       10284


6.  call a cfinclude setting a variable
    to the current index prior to the
    include

    -- index.cfm --

    <cfloop from="1" to="10000" index="i">
      <cfset number = i>
      <cfinclude template="cfinclude_test.cfm">
    </cfloop>

    -- cfinclude_test.cfm --

    <cfparam name="number" default="0">

    <cfoutput>
    #number#<br>
    </cfoutput>

    -- processing time --

    4897
      cfinclude:  1631
      index:      3336
    4867
      cfinclude:  1454
      index:      3473
    4837
      cfinclude:  1484
      index:      3413
    4816
      cfinclude:  1442
      index:      3424
    4967
      cfinclude:  1601
      index:      3416


i've tried to do my best, within the limitations of each method, to code
them as similarly as possible.  the numbers do not lie, there is definitely
a performance hit for using custom tags whether you call them via cfmodule
or as a custom tag, with or without an end tag.

obviously my example is alittle absurd in that it performs the specified
operation 10,000 times.  however, it pays to think about what the server is
likely to do in a situation of heavier load.

for a final bit of data, all of these tests were performed on my personal
machine with no outside traffic hitting the server.  it's a win2k box
running iis5 sp1, cf4.5.1 sp1 enterprise, p3 650mhz with 256 megs of ram.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: ... But for 99% of the work you do, this will
: not matter, and the benefits of custom tags
: (code re-use and readability) far outweigh
: the cost to performance.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i would say this statement is true if you've analyzed the necessity of using
a custom tag first.  if there's not another way of doing it then yes, i
would agree.

thanks,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org





More information about the thelist mailing list