Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Nifty Function of the Day -- Stopwatch

 [1/6] from: andrew:martin:colenso:school at: 19-Aug-2003 16:40


I needed something quick to time Rebol expressions (a number of Rebol words that work together), and I didn't want to put surrounding brackets around the Rebol code (yes, I am lazy). So I came up with this: Stopwatch: func [Label [string!] Start [time!] Value [any-type!]] [ print [now/time/precise - Start Label] ] And I use it like: StopWatch "Rearranging" now/time/precise foreach [ID Student] Students [ foreach [Date Entry] Student [ foreach [Period Code] Entry [ insert tail Intersections reduce [ make pair! reduce [ index? find/only Dates_Periods reduce [Date Period] index? find IDs ID ] Code ] ] ] ] And it gives me results like: 0:00:00.56 Reading/writing file 0:01:07.615 Parsing 0:00:26.557 Rearranging 0:00:00.401 Saving files (Which indicates that my parsing function needs to be improved if I'm to make this software faster!) Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [2/6] from: brett:codeconscious at: 19-Aug-2003 15:16


> I needed something quick to time Rebol expressions (a number of Rebol > words that work together), and I didn't want to put surrounding brackets > around the Rebol code (yes, I am lazy). So I came up with this:
That is nifty! Regards, Brett

 [3/6] from: AJMartin:orcon at: 19-Aug-2003 19:52


> 0:00:00.56 Reading/writing file > 0:01:07.615 Parsing > 0:00:26.557 Rearranging > 0:00:00.401 Saving files > > (Which indicates that my parsing function needs to be improved if I'm to
make this software faster!) After being a bit more smarter about my storage methods: 0:00:06.319 Parsing & storing 0:00:00.5 Rearranging 0:00:00.341 Saving YES! 60x faster in parsing & storing, and 60x faster in rearranging! Andrew J Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://Valley.150m.com/

 [4/6] from: greggirwin:mindspring at: 19-Aug-2003 9:40


Hi Andrew, AJM> YES! 60x faster in parsing & storing, and 60x faster in rearranging! Can you post the "before" and "after" code, or at least tell us what made the big difference? I always enjoy seeing how an optimization came about, why it works, and what the tradeoffs are. Also, any tricks that I can use to make my code faster are *always* appreciated. :) -- Gregg

 [5/6] from: andrew:martin:colenso:school at: 20-Aug-2003 9:11


Gregg wrote:
> Can you post the "before" and "after" code, or at least tell us what
made the big difference? Here's the statistics when running on the same machine (I used two different PCs before): Old %"Audit Trail.r": 0:01:08.348 Parsing 0:00:27.45 Rearranging New %"Audit Trail.r": 0:00:20.96 Parsing 0:00:01.262 Rearranging Part of Old %"Audit Trail.r": Audit_Entry: [ copy ID 3 skip ( ID: (to tuple! to binary! :ID) - 65 ID: ID/1 * 100 + ID/2 * 100 + ID/3 ID: to issue! ID ) copy Day 2 digit (Day: to integer! Day) #"/" copy Month 2 digit (Month: to integer! Month) copy Period digit (Period: to integer! Period) copy Code [alpha | SP] ( Code: either " " = Code [none] [to word! Code] ) ;copy Method 2 skip SP copy Previous skip "##" 2 skip SP skip "##" ] Students: make block! 1000 ; 4 periods/day; 5 days/week; 10 weeks/term; 4 terms/year; Dates_Periods: make block! 4 * 5 * 10 * 4 IDs: make block! 1000 Stopwatch "Parsing" now/time/precise parse/all Audit_Trail [ any [ Audit_Entry ( if not found? Student: select Students ID [ insert tail Students reduce [ID Student: make block! 1000] ] Date: make date! reduce [Day Month Year] itemize Dates_Periods reduce [Date Period] itemize IDs ID if not found? Entry: select Student Date [ insert tail Student reduce [Date Entry: make block! 8] ] associate Entry Period Code if empty? Entry [ associate Student Date none if empty? Student [ associate Students ID none ] ] ) ] end ] Intersections: make block! 120000 Stopwatch "Rearranging" now/time/precise foreach [ID Student] Students [ foreach [Date Entry] Student [ foreach [Period Code] Entry [ insert tail Intersections reduce [ make pair! reduce [ index? find/only Dates_Periods reduce [Date Period] index? find IDs ID ] Code ] ] ] ] Part of New %"Audit Trail.r": Dates: iota make date! reduce [1 1 year] make date! reduce [31 12 year] Date_Period: map Dates func [Date [date!]] [reduce [Date array/initial Periods []]] Stopwatch "Parsing" now/time/precise parse/all Audit_Trail [ any [ copy ID 3 skip copy Day 2 digit #"/" copy Month 2 digit copy Period digit copy Code [alpha | SP] 4 skip "##" ( ID: (to tuple! to binary! :ID) - 65 ID: ID/1 * 100 + ID/2 * 100 + ID/3 ID: to issue! ID Date: to date! reduce [to integer! Day to integer! Month Year] Period: to integer! Period Code: either " " = Code [none] [to char! Code] associate Date_Period/:Date/:Period ID Code ) ] end ] Absences: make block! 100000 Stopwatch "Rearranging" now/time/precise foreach [Date Period_ID_Code] Date_Period [ repeat Period length? Period_ID_Code [ foreach [ID Code] Period_ID_Code/:Period [ insert/only tail Absences reduce [ ID Date Period Code ] ] ] ] Note that Audit_Trail is a log of values and only the latest/last Code for a Day/Month, ID & Pupil is the right value. Earlier Codes are incorrect. I'm fairly sure that difference in speed is due to me creating most of the data structure ahead of time and using Rebol's path to access the ID Code block, for each Day & Period. And the next difference is changing to a table structure instead of using a list of pair! and Code values. Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [6/6] from: greggirwin::mindspring::com at: 19-Aug-2003 16:36


Thanks Andrew! I'll have to make some time to compare the two. --Gregg