Compare sorting algorithms' performance: Difference between revisions
Content added Content deleted
(Added Erlang) |
m (Added reversed range) |
||
Line 958: | Line 958: | ||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
The sort routines are borrowed from [http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort bubble sort], [http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort insertion sort] and [http://rosettacode.org/wiki/Sorting_algorithms/Quicksort quick sort]. Plots by [https://github.com/psyeugenic/eplot eplot]. |
The sort routines are borrowed from [http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort bubble sort], [http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort insertion sort] and [http://rosettacode.org/wiki/Sorting_algorithms/Quicksort quick sort]. Plots by [https://github.com/psyeugenic/eplot eplot]. |
||
Bubble sort does ones and ranges best. Insertion sort does the reversed range best. Quick sort handles shuffled numbers best. |
|||
<lang Erlang> |
<lang Erlang> |
||
-module( compare_sorting_algorithms_performance ). |
-module( compare_sorting_algorithms_performance ). |
||
Line 966: | Line 966: | ||
task() -> |
task() -> |
||
Ns = [100, 1000, 10000], |
Ns = [100, 1000, 10000], |
||
Lists = [{"ones", fun list_of_ones/1, Ns}, {"ranges", fun list_of_ranges/1, Ns}, {"shuffleds", fun list_of_shuffleds/1, Ns}], |
Lists = [{"ones", fun list_of_ones/1, Ns}, {"ranges", fun list_of_ranges/1, Ns}, {"reversed_ranges", fun list_of_reversed_ranges/1, Ns}, {"shuffleds", fun list_of_shuffleds/1, Ns}], |
||
Sorts = [{bubble_sort, fun bubble_sort:list/1}, {insertion_sort, fun sort:insertion/1}, {iquick_sort, fun quicksort:qsort/1}], |
Sorts = [{bubble_sort, fun bubble_sort:list/1}, {insertion_sort, fun sort:insertion/1}, {iquick_sort, fun quicksort:qsort/1}], |
||
Results = [time_list(X, Sorts) || X <- Lists], |
Results = [time_list(X, Sorts) || X <- Lists], |
||
Line 974: | Line 974: | ||
list_of_ones( N ) -> [1 || _X <- lists:seq(1, N)]. |
list_of_ones( N ) -> [1 || _X <- lists:seq(1, N)]. |
||
list_of_ranges( N ) -> [X || X <- lists:seq(1, N)]. |
list_of_ranges( N ) -> [X || X <- lists:seq(1, N)]. |
||
list_of_reversed_ranges( N ) -> lists:reverse( list_of_ranges(N) ). |
|||
list_of_shuffleds( N ) -> [random:uniform(N) || _X <- lists:seq(1, N)]. |
list_of_shuffleds( N ) -> [random:uniform(N) || _X <- lists:seq(1, N)]. |
||