Elapsed Time

Discussion in 'Programming' started by boothie, Aug 15, 2007.

  1. #1
    I'm trying to determine the elapsed time on a CF page.

    This is what I've tried:

    <cfset x = now()>
    .
    more code here...
    .
    <cfset elapsed_time = now() - x>

    <cfoutput> Time: #elapsed_time# </cfoutput>

    I get the following: Time: 1.15740767797E-005

    I've looked at Number/Decimal format functions, but then all I get is a 0.00

    TIA...
     
    boothie, Aug 15, 2007 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    is there anything triggering when the elapsed_time is calculated? if not the time 1.15740767797E-005 is probably the number of seconds it takes to run through the code between the two cfsets.

    if you want to though, you can use the datediff function and dateformat function to get things working a little more smoothly

    
    <cfset elapsed_time_seconds = datediff("s", x, now())>
    
    Code (markup):
    that would get the difference in seconds for you i believe.
    I don't know all that much about these functions but hopefully i've helped you on your path.
     
    Jamie18, Aug 16, 2007 IP
  3. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I usually use getTickCount() to calculate elapsed time. It returns milliseconds but you could easily convert it to seconds.

    
    not tested
    <cfset start = getTickCount() />
    ....
    
    <cfoutput>
    Time:  #(getTickCount() - start)#
    </cfoutput>
    
    Code (markup):
     
    cfStarlight, Aug 16, 2007 IP