Skip to content

Use std::chrono::steady_clock instead of gettimeofday in benchmarks#886

Open
0legmak wants to merge 1 commit into
cmu-db:masterfrom
0legmak:gettimeofday_to_steady_clock
Open

Use std::chrono::steady_clock instead of gettimeofday in benchmarks#886
0legmak wants to merge 1 commit into
cmu-db:masterfrom
0legmak:gettimeofday_to_steady_clock

Conversation

@0legmak
Copy link
Copy Markdown

@0legmak 0legmak commented May 16, 2026

gettimeofday can be adjusted backwards by the system, resulting in incorrect measurements. I see this quite often when running benchmarks under Windows 11 WSL. For example, this is a part of the btree-bench output:

[16.02] read   1: total_cnt=2473159    throughput=157948.052 avg_throughput=154418.019
[16.02] write  0: total_cnt=2353481    throughput=154348.651 avg_throughput=146945.617
[16.02] read   3: total_cnt=2482499    throughput=158494.505 avg_throughput=155001.186
[16.02] read   0: total_cnt=2466615    throughput=158377.622 avg_throughput=154009.428
[16.02] write  1: total_cnt=2333473    throughput=155284.715 avg_throughput=145696.366
[13.75] write  0: total_cnt=2407734    throughput=0.000      avg_throughput=175082.461
[13.75] write  1: total_cnt=2388271    throughput=0.000      avg_throughput=173679.805
[13.75] read   0: total_cnt=2523856    throughput=0.000      avg_throughput=183526.469
[13.75] read   3: total_cnt=2538817    throughput=0.000      avg_throughput=184614.383
[13.75] read   1: total_cnt=2528877    throughput=0.000      avg_throughput=183891.579
[13.75] read   2: total_cnt=2541115    throughput=0.000      avg_throughput=184781.486
[14.75] read   3: total_cnt=2699510    throughput=160532.468 avg_throughput=182980.411
[14.75] read   1: total_cnt=2690219    throughput=161180.819 avg_throughput=182350.641
[14.75] read   2: total_cnt=2703885    throughput=162607.393 avg_throughput=183276.961

Notice how the elapsed time goes back and a zero throughput.

std::chrono::steady_clock is recommended as the most suitable for measuring time intervals.

…rk tools. Previously used gettimeofday can be adjusted backwards, resulting in incorrect measurements.
@0legmak 0legmak force-pushed the gettimeofday_to_steady_clock branch from 8ba24f1 to 6cbc711 Compare May 16, 2026 11:00
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