Skip to content

Commit

Permalink
g-timer improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
oldk1331 committed Nov 5, 2023
1 parent e4597cf commit aa1ff99
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions src/interp/g-timer.boot
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,46 @@ makeLongStatStringByProperty _
total := 0
str := '""
otherStatTotal := GET('other, property)
roundingError := 0
for [name,class,:ab] in listofnames repeat
name = 'other => 'iterate
cl := first LASSOC(class, listofclasses)
n := GET(name, property)
PUT(cl, classproperty, n + GET(cl, classproperty))
total := total + n
if n >= 0.01
then timestr := normalizeStatAndStringify n
else
timestr := '""
otherStatTotal := otherStatTotal + n
str := makeStatString(str, timestr, name, flag)
PUT('other, property, otherStatTotal)
if otherStatTotal > 0 then
timestr := normalizeStatAndStringify otherStatTotal
str := makeStatString(str, timestr, 'other, flag)
total := total + otherStatTotal
cl := first LASSOC('other, listofnames)
cl := first LASSOC(cl, listofclasses)
PUT(cl, classproperty, otherStatTotal + GET(cl, classproperty))
name = 'other => 'iterate
if significantStat n then
str := makeStatString(str, n, name, flag)
else
roundingError := roundingError + n
str := makeStatString(str, otherStatTotal + roundingError, 'other, flag)
if flag ~= 'long then
total := 0
str := '""
for [class,name,:ab] in listofclasses repeat
n := GET(name, classproperty)
n = 0.0 or n = 0 => 'iterate
total := total + n
timestr := normalizeStatAndStringify n
str := makeStatString(str,timestr,ab,flag)
str := makeStatString(str, n, ab, flag)
total := STRCONC(normalizeStatAndStringify total,'" ", units)
str = '"" => total
STRCONC(str, '" = ", total)

normalizeStatAndStringify t ==
FLOATP t =>
t := roundStat t
t = 0.0 => '"0"
FORMAT(nil,'"~,2F",t)
significantStat t => FORMAT(nil, '"~,2F", t)
'"0"
INTEGERP t => FORMAT(nil, '"~:d", t)
STRINGIMAGE t

roundStat t ==
not FLOATP t => t
(TRUNCATE (0.5 + t * 1000.0)) / 1000.0
-- check if argument is significant enough to be printed.
-- current printing accuracy is 2 digits after decimal point.
significantStat t == t >= 0.005

makeStatString(oldstr,time,abb,flag) ==
time = '"" => oldstr
not significantStat time => oldstr
opening := (flag = 'long => '"("; '" (")
oldstr = '"" => STRCONC(time,opening,abb,'")")
STRCONC(oldstr,'" + ",time,opening,abb,'")")
timestr := normalizeStatAndStringify time
oldstr = '"" => STRCONC(timestr, opening, abb, '")")
STRCONC(oldstr, '" + ", timestr, opening, abb, '")")

peekTimedName() == IFCAR $timedNameStack

Expand Down

0 comments on commit aa1ff99

Please sign in to comment.