8
votes
Accepted
Digital clock with Python Tkinter
To start, it's crucial that you stop creating a brand new label ten times a second. Just modify the existing one. Also, this is so simple that a class is not called for. Move as much as possible away ...
6
votes
Python analog clock with turtle - runs slow
Avoid import *; there's only a few symbols you need from turtle.
There's a lot of repetition in your hand logic. Consider factoring out a class that does the common ...
6
votes
Accepted
Time duration conversion with units
Avoid defining your own constants
There's no need to use your own constants for the duration of a millisecond, second, minute and so on; just use the right ...
6
votes
Time duration conversion with units
Looks pretty good; these comments are mainly nitpicking:
Error messages should be streamed to std::cerr, not std::cout. Whilst ...
5
votes
Timer for event throttling
Using the following function to test, 62% of your CPU usage is used by DateTime.Now and 15% by Timer.Change
...
4
votes
Simple stop watch class
Silently ignoring a method call when it has been done in an invalid state should never be the correct approach. Calling start() when the stop watch has already been ...
4
votes
Accepted
A priority based timer using priority queue
any corner cases that I forgot to take into account
No error handling
e.g.: malloc() may return NULL.
any design approach that ...
3
votes
Retry a callback function n times until success
Super short review;
Pure nitpicking, but to me, you try the first time, and retry afterward. This means that a retry of 3 would guarantee up to 4 calls.
I would not create ...
3
votes
Python analog clock with turtle - runs slow
I found the correct way to optimize your code: the drawing code takes some time, so you should not wait 1 full second, but only wait until the time elapsed from the start of the loop is one second:
<...
3
votes
A priority based timer using priority queue
Code structure
There are three important components here
Priority queue
Scheduler
Timer
Scheduler picks up timer based on priority queue and fires.
Should priority queue know about details of Timer? ...
3
votes
Simple stop watch class
As mentioned in the comments, startTime is more sensible than startDate
in testing, I found ...
2
votes
Simple stopwatch in C
I think it's surprising that timeAdd() and timeDiff() return their results by both return value and out-parameter. I recommend ...
2
votes
A priority based timer using priority queue
There seems to be some confusion between this struct:
...
2
votes
Simple stop watch class
From the design perspective - have you considered making the class a pure function? I'd see its api like (keeping naming similar):
...
2
votes
Accepted
Simple stop watch class
For a library class, JavaDocs should be given (well, here the interface is so small and well-named that one can easily guess the tasks of the methods, but anyway).
As already said, the ...
2
votes
Simple stop watch class
A broader view of development scenario, skip it for a narrow approach of code reviewing. The code snippet from one of the answers to this question could be a unit test that is an easy maintainable ...
2
votes
Accepted
Leaky Bucket Algorithm with no Queue
Create a type alias for the clock you want to use
Things become more maintainable and easier to write if you create a type alias for the clock, like so:
...
2
votes
Accepted
Program to check if a window is opened or not during some time interval
I would probably start by defining a function named require or something on that order:
...
1
vote
Python analog clock with turtle - runs slow
Waiting 1 second at a time will never work well. The time in between sleep calls is not counted, so every tick will be slightly longer than 1 second, no matter what you do.
Instead you should track ...
1
vote
Simple stop watch class
to measure time without the need to deal with details of a time library
could be achieved following the Single-responsibility principle factoring out the conversion from nano seconds to a different ...
1
vote
Simple stop watch class
By the way is implemented the timing can be achieved in two steps: instantiate and start the timing thus it might worth addressing thread safeness that could be achieved in terms of listed ...
1
vote
Safe Windows API Timers for Excel
This is a pet peeve of mine:
s = s & "Public Sub Init(ByRef hWnd As LongPtr _" & n
I hate large blocks of code with this type of concatenation. ...
1
vote
Simple stop watch class
Update to question update: After updating the question most of the requirements exploratory answer is obsolete. Following up the updates there might be alternative solutions, although arguable from K....
1
vote
Accepted
watchdog for c++11
Move Event and TimeEvent inside class Timer
These types are just implementation details of ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
timer × 302javascript × 60
c# × 52
c++ × 44
java × 43
python × 36
beginner × 32
multithreading × 25
datetime × 22
c++11 × 19
performance × 17
jquery × 14
game × 14
c × 13
python-3.x × 10
object-oriented × 10
scheduled-tasks × 10
error-handling × 9
thread-safety × 9
swing × 9
animation × 9
android × 8
winforms × 8
benchmarking × 8
.net × 7