Created
May 30, 2023 12:50
-
-
Save jamessdixon/77b5fcddfe2c204790a2875ea57a2120 to your computer and use it in GitHub Desktop.
Using Higher Order Functions In Hypedsearch
This file contains 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
#original | |
def do_fourth_thing(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol): | |
start_time = time.time() | |
hybrid_merged = clustering.get_hybrid_matches(b_sorted_clusters, y_sorted_clusters, spectrum.precursor_mass, prec_tol, spectrum.precursor_charge) | |
end_time = time.time() - start_time | |
with open('Timing_data.txt', 'a') as t: | |
t.write("Finding hybrid merges took:" + '\t' + str(end_time) + "\n") | |
return hybrid_merged | |
#reduces to | |
def do_fourth_thing(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol): | |
hybrid_merged = clustering.get_hybrid_matches(b_sorted_clusters, y_sorted_clusters, spectrum.precursor_mass, prec_tol, spectrum.precursor_charge) | |
def write_metrics(func, spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol): | |
start_time = time.time() | |
func(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol) | |
end_time = time.time() - start_time | |
with open('Timing_data.txt', 'a') as t: | |
t.write("Finding hybrid merges took:" + '\t' + str(end_time) + "\n") | |
return hybrid_merged | |
write_metrics(do_fourth_thing,spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol) | |
#reduces to | |
def write_metrics(func, spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol): | |
start_time = time.time() | |
func(spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol) | |
end_time = time.time() - start_time | |
with open('Timing_data.txt', 'a') as t: | |
t.write("Finding hybrid merges took:" + '\t' + str(end_time) + "\n") | |
return hybrid_merged | |
write_metrics(clustering.get_hybrid_matches,spectrum, b_sorted_clusters, y_sorted_clusters, prec_tol) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment