Skip to content

Instantly share code, notes, and snippets.

@nickva
Created June 10, 2022 19:56
Show Gist options
  • Save nickva/708d0fd54cc7849dfd56ed0d0e508450 to your computer and use it in GitHub Desktop.
Save nickva/708d0fd54cc7849dfd56ed0d0e508450 to your computer and use it in GitHub Desktop.
Sorting an already sorted list in Erlang
% ./erlperf \
'runner(Unsorted) -> lists:sort(Unsorted).' \
--init_runner '[{rand:uniform(), I} || I <- lists:seq(1,500)].' \
'runner(Sorted) -> lists:sort(Sorted).' \
--init_runner 'lists:sort([{rand:uniform(), I} || I <- lists:seq(1,500)]).'
Code || QPS Time Rel
runner(Sorted) -> lists:sort(Sorted). 1 69223 14446 ns 100%
runner(Unsorted) -> lists:sort(Unsorted). 1 7158 140 us 10%
% ./erlperf \
'runner(Unsorted) -> lists:sort(Unsorted).' \
--init_runner '[{rand:uniform(), I} || I <- lists:seq(1,1000)].' \
'runner(Sorted) -> lists:sort(Sorted).' \
--init_runner 'lists:sort([{rand:uniform(), I} || I <- lists:seq(1,1000)]).'
Code || QPS Time Rel
runner(Sorted) -> lists:sort(Sorted). 1 30532 32752 ns 100%
runner(Unsorted) -> lists:sort(Unsorted). 1 2995 334 us 9%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment