Skip to content

Commit 68b4c23

Browse files
committed
updating qsort benchmark for issue #562
1 parent c462737 commit 68b4c23

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/perf/perf.jl

+24-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,31 @@ mandelperf() = [ mandel(complex(r,i)) | r=-2.0:.1:0.5, i=-1.:.1:1. ]
6262

6363
## numeric vector sort ##
6464

65+
function qsort_kernel(a, lo, hi)
66+
i = lo
67+
j = hi
68+
while i < hi
69+
pivot = a[ifloor((lo+hi)/2)]
70+
while i <= j
71+
while a[i] < pivot; i = i + 1; end
72+
while a[j] > pivot; j = j - 1; end
73+
if i <= j
74+
t = a[i]
75+
a[i] = a[j]
76+
a[j] = t
77+
i = i + 1
78+
j = j - 1
79+
end
80+
end
81+
if lo < j; qsort_kernel(a, lo, j); end
82+
lo = i
83+
j = hi
84+
end
85+
return a
86+
end
87+
6588
function sortperf(n)
66-
v = rand(n)
67-
sort!(v)
89+
qsort_kernel(rand(n), 1, n)
6890
end
6991
@assert issorted(sortperf(5000))
7092
@timeit sortperf(5000) "quicksort"

0 commit comments

Comments
 (0)