The clock problem - to if or not to if?
Posted
by
trejder
on Programmers
See other posts from Programmers
or by trejder
Published on 2013-11-09T20:31:37Z
Indexed on
2013/11/09
22:08 UTC
Read the original article
Hit count: 248
Performance
|conditions
Let's say, we have a simple digital clock. To "power" it, we use a routine executed every second. We update seconds part in it. But, what about minutes and hours part?
What is better / more professional / offers better performance:
Ignore all checking and update hour, minute and seconds part each time, every second.
Use
if
+ a variable for checking, if 60 (or 3600) seconds passed and update minute / hour part only at that precise moments.
This leads us to a question, what is better -- unnecessary drawings (first approach) or extra if
s?
I've just spotted a Javascript digital clock, one of millions similar on one of billions pages. And I noticed that all three parts (hours, minutes and seconds) are updated every second, though first changes its value only once per 3600 seconds and second once per 60 seconds.
I'm not to experienced developer, so I might me wrong. But everything, what I've learnt up until now, tells me, that if
are far better then executing drawing / refreshing sequences only to draw the same content.
© Programmers or respective owner