Skip to content

Modernize timing functions with C++11 std::chrono#854

Open
lemenkov wants to merge 3 commits intoSIPp:masterfrom
lemenkov:time_replacement
Open

Modernize timing functions with C++11 std::chrono#854
lemenkov wants to merge 3 commits intoSIPp:masterfrom
lemenkov:time_replacement

Conversation

@lemenkov
Copy link
Member

Replace legacy POSIX timing APIs with modern C++11 equivalents.

@orgads
Copy link
Contributor

orgads commented Feb 12, 2026

What's the point of removing update_clock_tick?

@lemenkov
Copy link
Member Author

What's the point of removing update_clock_tick?

I believe the original commit (1f5c3ba) made sense at the time - separating the side effect of updating clock_tick from getmilliseconds(), making the intent explicit. However, update_clock_tick() ended up as just oneliner that only assigns a value. This doesn't add much benefit, and made the code just as readable as clock_tick = getmilliseconds().

That said, this is a minor style preference - I am not going to insist on it and happy to revert that particulat part of this PR.

@wdoekes
Copy link
Member

wdoekes commented Feb 17, 2026

Comments are wrong now:

// Returns the number of microseconds that have passed since SIPp
// started. Also updates the current clock_tick.

and

// Returns the number of milliseconds that have passed since SIPp
// started. Also updates the current clock_tick.

[edit] p.s. I prefer update_clock_tick() over clock_tick = getmilliseconds(); -- add inline (moved to header) if you're worried about performance.

@lemenkov
Copy link
Member Author

Comments are wrong now:

// Returns the number of microseconds that have passed since SIPp
// started. Also updates the current clock_tick.

and

// Returns the number of milliseconds that have passed since SIPp
// started. Also updates the current clock_tick.

[edit] p.s. I prefer update_clock_tick() over clock_tick = getmilliseconds(); -- add inline (moved to header) if you're worried about performance.

I'm on it.

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
The sipp_usleep() function was a workaround for POSIX usleep() having
undefined behavior for values >= 1,000,000 microseconds. However:

- usleep() was deprecated in POSIX.1-2001 and removed in POSIX.1-2008
- C++11 std::this_thread::sleep_for() handles arbitrary durations correctly
- The function was only used in 3 places, none requiring microsecond precision

Replace with direct std::this_thread::sleep_for() calls using
appropriate std::chrono duration types.

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>
@lemenkov
Copy link
Member Author

Comments are wrong now:

// Returns the number of microseconds that have passed since SIPp
// started. Also updates the current clock_tick.

and

// Returns the number of milliseconds that have passed since SIPp
// started. Also updates the current clock_tick.

[edit] p.s. I prefer update_clock_tick() over clock_tick = getmilliseconds(); -- add inline (moved to header) if you're worried about performance.

They were wrong even before. I updated these comments in a separate commit before others.

Use std::chrono::steady_clock instead of clock_gettime() with
platform-specific workarounds. This removes:

- Obsolete macOS Mach clock workaround (clock_gettime available since 10.12)
- CLOCK_MONOTONIC_COARSE optimization (negligible performance impact)
- Legacy includes: time.h, sys/time.h, unistd.h, mach/clock.h, mach/mach.h

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Assisted-by: Claude (Anthropic) <https://claude.ai>
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.

3 participants