[REBOL] Re: Nifty Function of the Day -- Stopwatch
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]