Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My approach was focused on optimizing the file reading by aggressively minimizing memory allocations. I had the most fun optimizing this flow and then just added concurrency at the end. The only interesting bits are a simple custom
parseFloatFast
function and usingunsafe.String
in read-only use cases to avoid allocation of strings.I think it might be competitive. There is a pretty funny lesson to be learned here that everyone's solution is the fastest on their own machine 😄
1/18 Timing Update
Improved on my machine to 5.5s after adjusting buffer sizes using hyperfine testing. Tuned for 2023 Macbook M2 Pro
Original Timing
Top Java and Go solutions measured on a 2023 Apple M2 Pro Macbook with 10 cores and 16GB RAM.
* Measured w/ Docker Desktop turned off which was a drag with its 1GB RAM VM.
* Table and final benchmark were generated with different measurements_1B.txt files. Table was run on a measurements_1B.txt file generated around a week ago.
Shoutout to @AlexanderYastrebov who's push on supporting language-agnostic solutions motivated me to work on mine. And shoutout to @gunnarmorling. Excited to share with coworkers :)
Check List:
./test.sh <username>
shows no differences between expected and actual outputs)calculate_average_<username>.sh
(make sure to match casing of your GH user name) and is executablecalculate_average_baseline.sh
7.10s5.48s