Quicksort is said to be one of the most quick algorithms for sorting data inside a list/table/whatever. Anyway how comes the rosettacode Lua implementation of this algorithm
function quicksort(t)
if #t < 2 then return t end
local pivot = t[1]
local a, b, c={}, {}, {}
for _, v in ipairs(t) do
if v < pivot then a[#a + 1] = v
elseif v > pivot then c[#c + 1] = v
else b[#b + 1] = v
end
end
a = quicksort(a)
c = quicksort(c)
for _, v in ipairs(b) do a[#a + 1] = v end
for _, v in ipairs(c) do a[#a + 1] = v end
return a
end
is so much slower (takes about one minute to sort all the random placed entries in a one million entries table) compared to the built-in table.sort(table)
algorithm, wich only takes about five seconds to sort the same table?