Skip to content

Commit

Permalink
Merge pull request #29231 from haampie/quicksort-fewer-memops
Browse files Browse the repository at this point in the history
Sort the pivot, lo and hi value immediately in-place in quicksort
  • Loading branch information
pabloferz authored Sep 24, 2018
2 parents fa7d1a9 + 93091e7 commit 2a35981
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,26 +477,22 @@ end
@inbounds begin
mi = (lo+hi)>>>1

# sort the values in v[lo], v[mi], v[hi]

if lt(o, v[mi], v[lo])
# sort v[mi] <= v[lo] <= v[hi] such that the pivot is immediately in place
if lt(o, v[lo], v[mi])
v[mi], v[lo] = v[lo], v[mi]
end
if lt(o, v[hi], v[mi])
if lt(o, v[hi], v[lo])
v[lo], v[mi], v[hi] = v[hi], v[lo], v[mi]

if lt(o, v[hi], v[lo])
if lt(o, v[hi], v[mi])
v[hi], v[lo], v[mi] = v[lo], v[mi], v[hi]
else
v[hi], v[mi] = v[mi], v[hi]
v[hi], v[lo] = v[lo], v[hi]
end
end

# move v[mi] to v[lo] and use it as the pivot
v[lo], v[mi] = v[mi], v[lo]
pivot = v[lo]
# return the pivot
return v[lo]
end

# return the pivot
return pivot
end

# partition!
Expand Down

2 comments on commit 2a35981

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.