Bug 15766 - optimize os.date() calls in ClockApplet
: optimize os.date() calls in ClockApplet
Status: RESOLVED FIXED
Product: SqueezePlay
Classification: Unclassified
Component: Screensavers
: 7.5.x
: PC Other
: P3 normal (vote)
: 7.6.0
Assigned To: Michael Herger
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-02-24 07:24 UTC by Ben Klaas
Modified: 2010-07-19 12:47 UTC (History)
2 users (show)

See Also:
Category: Task


Attachments
patch to reduce os.date() calls (3.79 KB, patch)
2010-07-16 13:08 UTC, Ben Klaas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Klaas 2010-02-24 07:24:09 UTC
advice from Michael 24Feb2010 in Campfire:

Ben - you could probably reduce the number of os.date() calls in Clock by using the special format *t, returning a hash of values
date = os.date("*t")
if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1--12), day (1--31), hour (0--23), min (0--59), sec (0--61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean).

optimizing os.date() calls in  Clock is out of scope for 7.5.0, so opening this against 8.0 as a reminder
Comment 1 Ben Klaas 2010-07-16 12:25:24 UTC
I spent a little time with this for fun today...what ends up happening if you pull in the os.date("*t") hash is that you end up having to call tostring() a lot instead. I'm not sure which is more expensive, but I think the value of optimizing os.date() calls for tostring() calls is small enough to say WONTFIX.
Comment 2 Ben Klaas 2010-07-16 13:06:58 UTC
change of heart, this is probably worth doing
Comment 3 Ben Klaas 2010-07-16 13:08:47 UTC
Created attachment 6914 [details]
patch to reduce os.date() calls

Michael, can you try this patch out? I tested all of the clocks and everything seems good, but wanted another set of eyes on this before checking into 7.6/trunk
Comment 4 Michael Herger 2010-07-19 04:38:14 UTC
Looking good to me. What made you chang your mind?
Comment 5 Ben Klaas 2010-07-19 12:35:24 UTC
well, I'm not sure which is more expensive but I'd have to guess it's os.date(). I thought the code was cleaner with (usually) just one call to os.date() and misc string.format() and tostring() calls.

I think this is safe for a 7.6 checkin.
Comment 6 SVN Bot 2010-07-19 12:36:22 UTC
 == Auto-comment from SVN commit #8963 to the jive repo by bklaas ==
 == http://svn.slimdevices.com/jive?view=revision&revision=8963 ==

Fixed Bug: 15766
Description: optimize code to reduce os.date() calls by using the *t arg to it and then manipulating the returned hash
Comment 7 SVN Bot 2010-07-19 12:47:11 UTC
 == Auto-comment from SVN commit #8964 to the jive repo by bklaas ==
 == http://svn.slimdevices.com/jive?view=revision&revision=8964 ==

Bug: 15766
Description: need leading zeroes for several strings when number < 10
time.wday counts from 1 while strings.txt counts from 0