Repository navigation
Fair benchmark: identical inputs, correct counts, tests and CI - #1
Merged
Merged
Conversation
Each algorithm used to sort a different random array, once, at a single size, so the comparison was not fair. Now every algorithm gets an identical copy of each input at several sizes and in four orders (random, sorted, reversed, nearly sorted), and each is timed over five runs with a monotonic clock, reporting the median. Every result is checked to be sorted. Insertion sort never counted the comparison that ends its inner loop. All three algorithms now count comparisons and array writes the same way, and no longer count swapping an element with itself. bubble_sort no longer underflows when given an empty array. quick_sort takes the same arguments as the others and recurses into the smaller side, so sorted input cannot overflow the stack. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unit tests check each algorithm against qsort on random arrays with duplicates, and check exact comparison and write counts on sorted and reversed input. CI builds with GCC and Clang with warnings as errors, repeats the tests under AddressSanitizer and UBSan, runs the benchmark, and uploads the CSV and charts. visualize.py now saves PNG files instead of opening windows, and prints a Markdown summary table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reports the comparisons, writes and times measured in CI, explains what they show, and describes what the program measures without claiming to measure energy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What was wrong
clock()for a single run of a millisecond-scale task.n - 1underflowed.What changed
qsort, and check exact counts on sorted and reversed input.visualize.pysaves charts to files instead of opening windows.A follow-up commit on this PR rewrites the README with the numbers CI measures.
🤖 Generated with Claude Code