perf: Remove unused length computation in List.myers_difference - #15753
Merged
Conversation
Contributor
Author
Mix.install([{:benchee, "~> 1.4"}])
tag = System.get_env("TAG") || raise "set TAG, e.g. TAG=main or TAG=p03"
result_file = fn t -> Path.join(__DIR__, "p03_myers.#{t}.benchee") end
baselines = Path.wildcard(Path.join(__DIR__, "p03_myers.*.benchee")) -- [result_file.(tag)]
identical = Enum.to_list(1..1000)
small_edit = List.replace_at(identical, 500, :changed)
disjoint_a = Enum.to_list(1..200)
disjoint_b = Enum.to_list(1001..1200)
str_a = String.duplicate("abcdefghij", 100)
str_b = String.replace(str_a, "abcdefghij", "abcdeXghij", global: false)
Benchee.run(
%{
"identical 1000" => fn -> List.myers_difference(identical, identical) end,
"one edit 1000" => fn -> List.myers_difference(identical, small_edit) end,
"disjoint 200 (control)" => fn -> List.myers_difference(disjoint_a, disjoint_b) end,
"String.myers_difference" => fn -> String.myers_difference(str_a, str_b) end
},
warmup: 1,
time: 3,
memory_time: 1,
save: [path: result_file.(tag), tag: tag],
load: baselines
) |
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.
myers_difference_with_diff_script/3computedlength(list1) + length(list2)and threaded it throughfind_script/4,which never read it: the recursion is bounded by
each_diagonal/5finding the endpoint, which the Myers algorithm guarantees within
n + m iterations. Two full list traversals of dead work per call,
also paid by
String.myers_difference/2and ExUnit's diff output.Assisted by: Claude Fable.