Jump to content

Compare sorting algorithms' performance: Difference between revisions

m (no->not)
Line 1,457:
 
The data fit curves of the character cell graph were combined with GCD +. function. This explains "1"s or other strange values where these curves intersect. Finally the scatter plots were multiplied by infinity and added to the best fit curves. The points didn't show up well using the same values as the curves.
 
 
=={{header|Julia}}==
Julia comes with the InsertionSort, MergeSort, and QuickSort routines built into the Base.Sort module. Here is a comparison using those system algorithms and with integers.
<lang julia>
function comparesorts(tosort)
a = shuffle(["i", "m", "q"])
iavg = mavg = qavg = 0.0
for c in a
if c == "i"
iavg = sum(i -> @elapsed(sort(tosort, alg=InsertionSort)), 1:100) / 100.0
elseif c == "m"
mavg = sum(i -> @elapsed(sort(tosort, alg=MergeSort)), 1:100) / 100.0
elseif c == "q"
qavg = sum(i -> @elapsed(sort(tosort, alg=QuickSort)), 1:100) / 100.0
end
end
iavg, mavg, qavg
end
 
allones = fill(1, 40000)
sequential = collect(1:40000)
randomized = collect(shuffle(1:40000))
 
comparesorts(allones)
comparesorts(allones)
iavg, mavg, qavg = comparesorts(allones)
println("Average sort times for 40000 ones:")
println("\tinsertion sort:\t$iavg\n\tmerge sort:\t$mavg\n\tquick sort\t$qavg")
 
comparesorts(sequential)
comparesorts(sequential)
iavg, mavg, qavg = comparesorts(sequential)
println("Average sort times for 40000 presorted:")
println("\tinsertion sort:\t$iavg\n\tmerge sort:\t$mavg\n\tquick sort\t$qavg")
 
comparesorts(randomized)
comparesorts(randomized)
iavg, mavg, qavg = comparesorts(randomized)
println("Average sort times for 40000 randomixed:")
println("\tinsertion sort:\t$iavg\n\tmerge sort:\t$mavg\n\tquick sort\t$qavg")
</lang>
<pre>Average sort times for 40000 ones:
insertion sort: 0.00036058316000000005
merge sort: 0.00040099004999999996
quick sort 0.0003586394400000001
Average sort times for 40000 presorted:
insertion sort: 0.0003141142199999999
merge sort: 0.0007967360000000003
quick sort 0.0005601127399999998
Average sort times for 40000 randomixed:
insertion sort: 0.2190664327599999
merge sort: 0.0028818907399999986
quick sort 0.0023325933899999997
</pre>
 
=={{header|Kotlin}}==
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.