Skip to content

feat(js/ts): support System.Diagnostics.Stopwatch - #5100

Merged
MangelMaxime merged 2 commits into
fable-compiler:mainfrom
simontreanor:stopwatch
Oct 21, 2026
Merged

MangelMaxime merged 2 commits into
fable-compiler:mainfrom
simontreanor:stopwatch

Conversation

@simontreanor

Copy link
Copy Markdown
Contributor

This fixes #5099 by adding System.Diagnostics.Stopwatch to the JS/TS target, built on performance.now() (with Date.now() as a fallback if it's ever missing).

The new Stopwatch.ts keeps the time measured before the last Start plus the time it was started, so Stop and Start accumulate like .NET. Timestamps and ElapsedTicks are in microseconds, the resolution performance.now() offers, so Frequency is 1,000,000, the same as on Beam. Elapsed and GetElapsedTime go through fromMilliseconds in the TimeSpan module, so they work with Temporal too. Frequency and IsHighResolution are static fields on .NET, so they're handled in tryField.

The tests are in MiscTests.fs and cover the statics, StartNew, Elapsed, Start/Stop/Reset and Restart. ./build.sh test javascript (including the Temporal run) and ./build.sh test typescript pass, and the new tests pass on .NET as well.

@MangelMaxime

Copy link
Copy Markdown
Member

Thank you for the PR.

I made a quick pass and would like to add some small improvements myself. I will not be able to do it before the beginning of next week, so I am converting it to draft in the meantime to prevent an accidental merge.

No action is needed from you.

@MangelMaxime
MangelMaxime marked this pull request as draft October 16, 2026 20:41
simontreanor and others added 2 commits October 21, 2026 19:47
Built on performance.now(), as the Python and Beam targets already
support Stopwatch.

Fixes fable-compiler#5099
@MangelMaxime
MangelMaxime marked this pull request as ready for review October 21, 2026 17:55
@MangelMaxime
MangelMaxime merged commit eb68225 into fable-compiler:main Oct 21, 2026
35 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.

[JS/TS] Support System.Diagnostics.Stopwatch

2 participants