Skip to content

Conversation

@jpco
Copy link
Collaborator

@jpco jpco commented Sep 6, 2025

This PR is a smaller part of #210, which came from the discussion in #154. I'm not sure about the git history; this PR might be best merged squashed.

It's a fairly heavy refactor of $&time which is, I think, quite a bit clearer, and does a better job than before of handling the messy set of time library functions available. It's not perfect -- gettimeofday(3) is listed as "obsolescent" in the man page -- but swapping out functions is easy with the proposed setup.

In part because of the better time library handling, it also reports times in milliseconds (real-time measurements might be in seconds on machines with don't have gettimeofday(3), though I don't think there are a lot of those.)

; es.old -c 'time sleep 0.1'
     0r     0.0u     0.0s	sleep 0.1
; es.new -c 'time sleep 0.1'
 0.101r   0.001u   0.000s	sleep 0.1

I'd still like those other changes from #210 at some point. This is just the part I feel actively impatient about: in my view, es time is almost useless without millisecond precision.

jpco added 10 commits April 28, 2025 08:22
 - Clean up time code to be much more legible
 - Use intmax_t for timestamps to be more overflow-resistant
 - Add fallback for time functions
 - Add error handling
This uses the (AFAICT) previously-unused 'dotconv' for a new purpose.
If an  integer (for example, 8675309) is printed with "%.3d", the output
is 8675.309, putting three decimal places after the point.  This is a
bit weird, but it avoids any complexity around non-integer numbers.
"Forkless" time and being able to compare arbitrary code points are neat
and good, but more straightforwardly useful are improvements to timing
precision and clean standard time library handling.
@jpco jpco force-pushed the master branch 4 times, most recently from 64361a8 to a23a7a0 Compare September 19, 2025 00:40
@jpco
Copy link
Collaborator Author

jpco commented Dec 12, 2025

In order to try to have our cake and eat it too, I have wrapped the millisecond-precision part of this behind a build define, -DMILLISECOND_TIME=1. If you build with that flag, then you'll get millisecond-precision times printed from $&time, and if you don't, then es will default to its current behavior.

This doesn't leave the default behavior perfectly backwards-compatible, since it changes some error-handling behavior and might change certain edge cases around printing times, but I believe it's satisfactorily backwards-compatible to merge now.

@jpco jpco merged commit beec36c into wryun:master Dec 12, 2025
1 check passed
@jpco jpco deleted the precisetime branch December 12, 2025 17:01
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.

1 participant