Torch quicksort can be extremely slow

111 views
Skip to first unread message

Michael M

unread,
Mar 14, 2013, 4:20:15 PM3/14/13
to tor...@googlegroups.com
Hi all,

I've just noticed that the implementation of quick sort in torch is not randomized. Since the complexity of quick sort can be O(n^2) if the list is already sorted (and this is a case that actually happens, otherwise I wouldn't have noticed...), the sort function can become extremely slow.
I have a sample code :

require 'sys'
n = 100000
a = torch.linspace(1,n,n)
b = torch.randperm(n)
sys.tic()
b:sort()
print("random list : "..sys.toc().." seconds.")
a:sort()
print("sorted list : "..sys.toc().." seconds.")

Which outputs :

random list : 0.01768599999923 seconds.
sorted list : 3.8866019999987 seconds.

Four seconds to sort 100 thousands elements is simply ridiculous.

I wonder why the sorting function re-implements a quick sort instead of using C/C++ standard functions, namely qsort/sort .

Best,
Michael
Reply all
Reply to author
Forward
0 new messages