Skip to content

Allow TIMER accuracy below one millisecond - #798

Merged
grymmjack merged 1 commit into
QB64-Phoenix-Edition:mainfrom
grymmjack:timer-sub-millisecond
Oct 25, 2026
Merged

grymmjack merged 1 commit into
QB64-Phoenix-Edition:mainfrom
grymmjack:timer-sub-millisecond

Conversation

@grymmjack

Copy link
Copy Markdown
Contributor

Fixes #797

TIMER(accuracy) always started from whole milliseconds, so TIMER(.000001) was never finer than 1 ms.

Change (internal/c/libqb/src/datetime.cpp)

  • millis_since_midnight() becomes micros_since_midnight().
  • An accuracy finer than .001 uses the microsecond value.
  • TIMER, TIMER(.001) and coarser accuracies use micros / 1000, the same truncated millisecond value as before, so their results don't change.
  • The accuracy <= 0 error check moved to the top so it still runs before the clock is read.

Test

tests/compile_tests/timer/timer_sub_millisecond.bas checks four things:

  • TIMER(.001) is still whole milliseconds.
  • TIMER(.000001) has sub-millisecond digits.
  • TIMER(.000001) never runs backwards (ignoring the midnight wrap).
  • The two agree with each other.

On main it fails with "only whole milliseconds"; with this change it passes.

Tested on

  • Linux (Debian 13): the timer test category passes.
  • macOS (Apple M2 Pro): the timer test category passes.
  • Windows 11: built and ran the new test by hand; it passes.

The measured tick of TIMER(.000001) is about 1 µs on all three. A smooth-motion test (ball moved in SUB _GL by elapsed time) that stuttered on a 120 Hz Mac with TIMER(.001) runs smoothly with TIMER(.000001) on all three.

Docs: the wiki's TIMER page would need a line saying accuracies below .001 now work.

🤖 Generated with Claude Code

TIMER(accuracy) always started from a whole number of milliseconds, so
TIMER(.0001) or TIMER(.000001) could never be finer than 1 ms. That is
too coarse for frame timing on high refresh rate displays (8.3 ms per
frame at 120 Hz).

The time is now read in microseconds. An accuracy finer than .001 uses
it; TIMER, TIMER(.001) and coarser accuracies keep the exact whole
millisecond value they returned before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@grymmjack
grymmjack merged commit e6bcbd4 into QB64-Phoenix-Edition:main Oct 25, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TIMER can't be finer than 1 ms - TIMER(.000001) still returns whole milliseconds

3 participants