Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.4
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      2

      Description

      A macro for timing a block of code. Could it be added to standard distribution?

      // sets "elapsed" to elapsed time
      timer elapsed:
      pass
      Output:
      _startTime1_ = System.DateTime.get_Now()
      elapsed = System.DateTime.op_Subtraction(System.DateTime.get_Now(), _startTime1_)

      // prints "Elapsed time: ${__elapsedTime

      {0}

      __}"
      timer:
      pass

      Output:
      _startTime2_ = System.DateTime.get_Now()
      _elapsedTime2_ = System.DateTime.op_Subtraction(System.DateTime.get_Now(), _startTime2_)
      System.Console.Write('Elapsed time: ')
      System.Console.WriteLine(_elapsedTime2_)

      1. TimeItMacro.patch
        12 kB
        Sorin Ionescu
      2. TimerMacro.cs
        7 kB
        Bill Wood

        Activity

        Hide
        Bill Wood added a comment -

        Latest attachment properly inherits from AbstractAstMacro

        Show
        Bill Wood added a comment - Latest attachment properly inherits from AbstractAstMacro
        Hide
        Sorin Ionescu added a comment -

        Completely rewritten.
        Usage: timeIt [label] [, iterations] [, elapsed]

        Example with all arguments.
        NOTE: The label argument is ignored if you pass the last argument.

        elapsed as timespan
        timeIt "Loop", 10, elapsed:
        index = 0
        while (index < 50000):
        ++index

        Show
        Sorin Ionescu added a comment - Completely rewritten. Usage: timeIt [label] [, iterations] [, elapsed] Example with all arguments. NOTE: The label argument is ignored if you pass the last argument. elapsed as timespan timeIt "Loop", 10, elapsed: index = 0 while (index < 50000): ++index
        Hide
        Doug H added a comment -

        I changed the regex in your test fixture to \d*?:\d*?:\d*?\.?\d*
        instead of \d*?:\d*?:\d*?\.\d*
        (put a question mark after last period)
        Because time was being printed like 00:00:00 instead of 00:00:00.00

        Show
        Doug H added a comment - I changed the regex in your test fixture to \d*?:\d*?:\d*?\.?\d* instead of \d*?:\d*?:\d*?\.\d* (put a question mark after last period) Because time was being printed like 00:00:00 instead of 00:00:00.00
        Hide
        Bill Wood added a comment -

        Doug,

        I'm afraid I can't vouch for this macro anymore - it was rewritten in Boo, and I think (from a short code inspection) that it will not be accurate anymore. In the C# version, I went to a lot of trouble to do loop unrolling so that the overhead of looping would not interfere with the results. In the Boo version, there is no loop unrolling, and also the elapsed time seems to be incremetally calculated within the loop, which due to the low system clock resolution will totally throw things off.

        • Bill
        Show
        Bill Wood added a comment - Doug, I'm afraid I can't vouch for this macro anymore - it was rewritten in Boo, and I think (from a short code inspection) that it will not be accurate anymore. In the C# version, I went to a lot of trouble to do loop unrolling so that the overhead of looping would not interfere with the results. In the Boo version, there is no loop unrolling, and also the elapsed time seems to be incremetally calculated within the loop, which due to the low system clock resolution will totally throw things off. Bill
        Hide
        Doug H added a comment -

        Yeah I liked the unroll feature too. I or Sorin will look into fixing the macro.
        If anyone wants to try Bill's original timer macro, just drop the .cs file attached to this jira issue into boo's src/boo.lang.compiler/macros/ folder and recompile boo.

        Show
        Doug H added a comment - Yeah I liked the unroll feature too. I or Sorin will look into fixing the macro. If anyone wants to try Bill's original timer macro, just drop the .cs file attached to this jira issue into boo's src/boo.lang.compiler/macros/ folder and recompile boo.

          People

          • Assignee:
            Unassigned
            Reporter:
            Bill Wood
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: