You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmp: count lines only when they are printed, and count them faster - #427
After each equal chunk, cmp counted the newlines in it one byte at a time, even with -s and -l, which never print a line number. That counting was most of cmp's CPU time.
Count lines only in the default mode, the only one that prints them.
Count them in 255-byte chunks summed in a u8, which the compiler vectorizes.
Two 300 MB files that differ at 250 MB, and a 40 MB text file (hyperfine, 10 runs, tmpfs):
GNU cmp 3.10
main
this PR
cmp a b
87.8 ms
168.4 ms
78.4 ms
cmp -s a b
88.0 ms
168.5 ms
79.0 ms
cmp -l a b
88.1 ms
171.2 ms
81.8 ms
text, 2M lines
12.9 ms
26.6 ms
11.2 ms
Output, error messages and exit codes match main for -s, -l, -b, -n, -i, EOF and equal files. The GNU testsuite gives the same results before and after, and the cmp fuzzers ran clean for 90 s each. A new test checks the line number after 30,000 lines, for a difference and for EOF.
System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.
⚠️8 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
⚠️8 benchmarks with a significant change ran in a different software environment
Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing KrushnXGIT:cmp-count-lines-only-when-needed (f0d5b99) with main (824dfcf)
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
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.
After each equal chunk, cmp counted the newlines in it one byte at a time, even with
-sand-l, which never print a line number. That counting was most of cmp's CPU time.u8, which the compiler vectorizes.Two 300 MB files that differ at 250 MB, and a 40 MB text file (hyperfine, 10 runs, tmpfs):
cmp a bcmp -s a bcmp -l a bOutput, error messages and exit codes match main for -s, -l, -b, -n, -i, EOF and equal files. The GNU testsuite gives the same results before and after, and the cmp fuzzers ran clean for 90 s each. A new test checks the line number after 30,000 lines, for a difference and for EOF.