Results 1 to 13 of 13

Thread: More Accurate Timekeeping

  1. #1
    Join Date
    Jun 2006
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default More Accurate Timekeeping

    Currently, I am using MarkTime() and TimeFromMark() to measure the length of object-finding functions. However, the only two results I ever seem to get is 0ms or 16ms.

    Is there a more exact timekeeping function I could use?

  2. #2
    Join Date
    Sep 2007
    Location
    Pennsylvania
    Posts
    3,396
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    In SRL it seems the most common method is using GetSystemTime, something like

    t := GetSystemTime;
    repeat
    //do action
    until(GetSystemTime - t > 5000);

    Would be worth a try. Though I use TimeFromMark and MarkTime as well

    EDIT: Appears they are the same thing
    Last edited by Runescapian321; 08-20-2009 at 10:32 PM.

  3. #3
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

  4. #4
    Join Date
    Jun 2006
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Alright, I'll give that a shot, thanks =)

  5. #5
    Join Date
    Aug 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    what i do to time functions is:

    Code:
    c:=GetSystemTime();
    //code to time goes here
    c:=GetSystemTime()-c;
    writeln('[file/functionName()] Execution Time: ' + IntToStr(c) );
    Works well for me.

  6. #6
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Let the code to speak!

    SCAR Code:
    {*******************************************************************************
    procedure MarkTime(var TimeMarker: Integer);
    By: Stupid3ooo
    Description: Sets TimeMarker to current system time
    *******************************************************************************}


    procedure MarkTime(var TimeMarker: Integer);
    begin
      TimeMarker := GetSystemTime;
    end;

    {*******************************************************************************
    function TimeFromMark(TimeMarker: Integer): Integer;
    By: Stupid3ooo
    Description: returns Milliseconds since MarkTime was set
    *******************************************************************************}


    function TimeFromMark(TimeMarker: Integer): Integer;
    begin
      Result := GetSystemTime - TimeMarker;
    end;

    Yes, MarkTime and TimeFromMark does the same as you. So your have to he same 16ms thing, I suppose.

  7. #7
    Join Date
    Aug 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    Let the code to speak!

    SCAR Code:
    {*******************************************************************************
    procedure MarkTime(var TimeMarker: Integer);
    By: Stupid3ooo
    Description: Sets TimeMarker to current system time
    *******************************************************************************}


    procedure MarkTime(var TimeMarker: Integer);
    begin
      TimeMarker := GetSystemTime;
    end;

    {*******************************************************************************
    function TimeFromMark(TimeMarker: Integer): Integer;
    By: Stupid3ooo
    Description: returns Milliseconds since MarkTime was set
    *******************************************************************************}


    function TimeFromMark(TimeMarker: Integer): Integer;
    begin
      Result := GetSystemTime - TimeMarker;
    end;

    Yes, MarkTime and TimeFromMark does the same as you. So your have to he same 16ms thing, I suppose.
    Seems like these methods are a waste of code! Why have functions that have only one simple line of code? I could understand if they were meant to simplify other code, but this is not the case here. Maybe someone else could clarify for me?

  8. #8
    Join Date
    Mar 2007
    Posts
    3,116
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by sixfeetunder View Post
    Seems like these methods are a waste of code! Why have functions that have only one simple line of code? I could understand if they were meant to simplify other code, but this is not the case here. Maybe someone else could clarify for me?
    Removing them now would break so many scripts

  9. #9
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by sixfeetunder View Post
    Seems like these methods are a waste of code! Why have functions that have only one simple line of code? I could understand if they were meant to simplify other code, but this is not the case here. Maybe someone else could clarify for me?
    Actually, they are meant to simplify other code. It's much more easier (and much more understandable) to do MarkTime(Variable) and TimeFromMark(Variable) than Variable := GetSystemTime and GetSystemTime - Variable.

  10. #10
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Actually, they are meant to simplify other code. It's much more easier (and much more understandable) to do MarkTime(Variable) and TimeFromMark(Variable) than Variable := GetSystemTime and GetSystemTime - Variable.
    Agree.
    In some cases like this it is good to have few line functions/procedures.

  11. #11
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    For benchmarking, just do like marktime, for i := 0 to 9999 do ..., writeln(inttostr(timefrommark/10000)); or something along the way.

  12. #12
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by sixfeetunder View Post
    Seems like these methods are a waste of code! Why have functions that have only one simple line of code? I could understand if they were meant to simplify other code, but this is not the case here. Maybe someone else could clarify for me?
    You are going seriously hate reading my scripts then. I will do stuff like this to make it more readable (to me at least):

    Code:
    const
      SUCCESS = TRUE;
      FAIL = FALSE;
    
    if (DoSomeAction() = FAIL) then
      { Take corrective action here }
    And my clay softener literally has a line that reads like this (I kid you not):

    Code:
    for WaterType := WATERJUG to WATERBUCKET do

  13. #13
    Join Date
    Jun 2006
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    For benchmarking, just do like marktime, for i := 0 to 9999 do ..., writeln(inttostr(timefrommark/10000)); or something along the way.
    Well, I'm not using this for benchmarking. My debug prints out the time it took to use functions during runtime.

    Thanks, though. I will keep that in mind when I do benchmark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •