jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
Boo
  • Boo
  • BOO-170

Timer macro

  • Log In
  • Views
    • XML
    • Word
    • Printable

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_)

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    TimeItMacro.patch
    29/May/05 9:41 AM
    12 kB
    Sorin Ionescu
  2. File
    TimerMacro.cs
    11/Dec/04 5:15 PM
    7 kB
    Bill Wood

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Bill Wood added a comment - 31/Oct/04 3:52 PM

Timer macro source code attached

Show
Bill Wood added a comment - 31/Oct/04 3:52 PM Timer macro source code attached
Hide
Permalink
Bill Wood added a comment - 31/Oct/04 3:55 PM

Corrected error in comment - please use this one.

Show
Bill Wood added a comment - 31/Oct/04 3:55 PM Corrected error in comment - please use this one.
Hide
Permalink
Bill Wood added a comment - 01/Nov/04 12:31 AM

Another improvement; this one allows a string of user's choice - example:

timer "Overall elapsed time: ":
timer:
for i in range(len(x.a)):
x.a[i] = i

timer elapsed:
for i in range(len(x.a2)):
x.a2[i] = i
print "Elapsed = $

{elapsed}

"

Output:
Elapsed time: 00:00:00.6208928
elapsed = 00:00:00.6309072
Overall elapsed time: 00:00:02.2832832

Show
Bill Wood added a comment - 01/Nov/04 12:31 AM Another improvement; this one allows a string of user's choice - example: timer "Overall elapsed time: ": timer: for i in range(len(x.a)): x.a [i] = i timer elapsed: for i in range(len(x.a2)): x.a2 [i] = i print "Elapsed = $ {elapsed} " Output: Elapsed time: 00:00:00.6208928 elapsed = 00:00:00.6309072 Overall elapsed time: 00:00:02.2832832
Hide
Permalink
Bill Wood added a comment - 01/Nov/04 12:51 AM

Sorry - forgot to update help string too.

Show
Bill Wood added a comment - 01/Nov/04 12:51 AM Sorry - forgot to update help string too.
Hide
Permalink
Bill Wood added a comment - 06/Nov/04 12:07 AM

New version takes optional argument for number of times to loop over code. It does loop unrolling to minimize impact of loop code on timer (default is to repeat code 8 times within loop body). The loop code is very fast (doesn't use iterator, its just a simple loop). This macro is the most accurate way to time things.

New syntax:

timer [nLoops [, unroll]] [, "Message: "] [, elapsedTimeVar]

Example:

timer 1000002:
f = fact(20)

generates this code:
_startTime1_ = System.DateTime.get_Now()
_loopCounter1_ = 0
while (_loopCounter1_ < 125000):
_loopCounter1_ = (_loopCounter1_ + 1)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
f = UntitledModule.fact(20)
_elapsedTime1_ = System.DateTime.op_Subtraction(System.DateTime.get_Now(), _startTime1_)
System.Console.Write('Elapsed time for 1000003 executions: ')
System.Console.WriteLine(_elapsedTime1_)

Show
Bill Wood added a comment - 06/Nov/04 12:07 AM New version takes optional argument for number of times to loop over code. It does loop unrolling to minimize impact of loop code on timer (default is to repeat code 8 times within loop body). The loop code is very fast (doesn't use iterator, its just a simple loop). This macro is the most accurate way to time things. New syntax: timer [nLoops [, unroll] ] [, "Message: "] [, elapsedTimeVar] Example: timer 1000002: f = fact(20) generates this code: _ startTime1 _ = System.DateTime.get_Now() _ loopCounter1 _ = 0 while (_ loopCounter1 _ < 125000): _ loopCounter1 _ = (_ loopCounter1 _ + 1) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) f = UntitledModule.fact(20) _ elapsedTime1 _ = System.DateTime.op_Subtraction(System.DateTime.get_Now(), _ startTime1 _) System.Console.Write('Elapsed time for 1000003 executions: ') System.Console.WriteLine(_ elapsedTime1 _)
Hide
Permalink
Bill Wood added a comment - 06/Nov/04 12:11 AM

Printed message in code above should read "1000002 executions" not "1000003 executions".

Show
Bill Wood added a comment - 06/Nov/04 12:11 AM Printed message in code above should read "1000002 executions" not "1000003 executions".
Hide
Permalink
Bill Wood added a comment - 11/Dec/04 5:15 PM

Latest attachment properly inherits from AbstractAstMacro

Show
Bill Wood added a comment - 11/Dec/04 5:15 PM Latest attachment properly inherits from AbstractAstMacro
Hide
Permalink
Sorin Ionescu added a comment - 29/May/05 9:41 AM

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 - 29/May/05 9:41 AM 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
Permalink
Doug H added a comment - 03/Nov/05 12:36 AM

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 - 03/Nov/05 12:36 AM 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
Permalink
Bill Wood added a comment - 03/Nov/05 8:38 AM

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 - 03/Nov/05 8:38 AM 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
Permalink
Doug H added a comment - 03/Nov/05 9:10 AM

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 - 03/Nov/05 9:10 AM 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
Vote (0)
Watch (1)

Dates

  • Created:
    31/Oct/04 3:51 PM
    Updated:
    03/Nov/05 9:10 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.