Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Use hyperfine instead of time to perform timing measurements #105

Closed
christianhujer opened this issue Jan 4, 2024 · 8 comments

Comments

@christianhujer
Copy link

Suggestion: Use hyperfine instead of time for performing timing measurements. It can automatically perform multiple runs and print statistical timing data on those runs.

Maybe I'll find time on the weekend to provide a PR for this.

@hundredwatt
Copy link
Contributor

hundredwatt commented Jan 5, 2024

I made a script using hyperfine that also calculates the result how this challenge prescribes:

TEMP_FILE=$(mktemp)
OPTS="--warmup 2 --runs 5 --export-json $TEMP_FILE"
JAVA_OPTS=""

hyperfine $OPTS \
        'java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_hundredwatt' \
        'java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_<COMPARE TO FORK>'

# The slowest and the fastest runs are discarded
# The mean value of the remaining three runs is the result for that contender
jq -r '.results[] | .command, ((.times | sort) | .[1:-1] | add / length)' $TEMP_FILE

@gunnarmorling
Copy link
Owner

Oh, very cool! Could you PR this script? I probably shouldn't change the way of evaluating in the middle of the challenge, but it's good to have for future reference and ad-hoc testing. Thx!

@hundredwatt
Copy link
Contributor

Sure! Here's the PR: #182

@gunnarmorling
Copy link
Owner

Awesome, thanks. That's a great start. We'd have to factor out though the call to sdk used by some of the contenders to enable a specific JDK distro, as that adds a non-insignificant overhead. Is there some sort of pre-run hook one could use for that? Similar for the additional_build_steps script needed for the native image entries.

@hundredwatt
Copy link
Contributor

hundredwatt commented Jan 8, 2024

Yes, hyperfine supports individual prepare commands, so we could do:

hyperfine $OPTS \
  --prepare './prepare_<fork1>.sh' \
  './calculate_average_<fork1>.sh' \
  --prepare './prepare_<fork2>.sh' \
  './calculate_average_<fork2>.sh'

But we still need to solve the sdkman issue (https://twitter.com/jasonnochlin/status/1744399656266629365)

@hundredwatt
Copy link
Contributor

Resolved on Twitter (https://twitter.com/gunnarmorling/status/1744413791272468607):

source ./prepare_<fork>.sh # jdk use... if present
additional_build_steps_<fork>.sh # if present
hyperfine 'calculate_average_<fork>.sh' # sets JAVA_OPTS and runs

@gunnarmorling
Copy link
Owner

Done. Thx a lot, @hundredwatt, great work! Makes the eval process much, much smoother now!

@hundredwatt
Copy link
Contributor

My less than 10 line POC above has turned into a 300 line behemoth 😂

I hope I made managing this contest a little less tedious for you @gunnarmorling! Thanks again for creating it!

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

No branches or pull requests

3 participants