Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shared pre-computation for by and perm orderings. #52033

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add performance tests
  • Loading branch information
Lilith Hafner authored and Lilith Hafner committed Nov 5, 2023
commit 0762aecf6543bd5679501495dc514e76059fb060
44 changes: 44 additions & 0 deletions test/sorting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,50 @@ end
@test issorted(sort!(rand(100), Base.Sort.InitialOptimizations(DispatchLoopTestAlg()), Base.Order.Forward))
end

@testset "Performance (how many timems By is called)" begin
# Intentional regressions are acceptable, accedental regressions are not.
cnt = Ref(0)
incr_identity = x -> (cnt[] += 1; x)
x = 1:50

cnt[] = 0
@test issorted(x; by=incr_identity)
@test cnt[] == 50 # Any less would be buggy.

cnt[] = 0
@test !issorted(x; by=incr_identity, rev=true)
@test cnt[] == 2 # Any less would be buggy.

cnt[] = 0
@test searchsortedfirst(x, 1; by=incr_identity) == 1
@test cnt[] <= 7

cnt[] = 0
@test searchsorted(repeat(1:10, inner=10), 3; by=incr_identity) == 21:30
@test cnt[] <= 16

cnt[] = 0
@test sort(x; by=incr_identity) == x
@test cnt[] <= 98

cnt[] = 0
@test sort(1:1000; by=incr_identity) == 1:1000
@test cnt[] <= 1998

cnt[] = 0
Random.seed!(1729)
x = randperm(1000)
@test sort!(x; by=incr_identity) == 1:1000
# This should succeed at least 99.99% of the time on random inputs
# and therefore should not be broken by changes to the rng
@test cnt[] <= 17203

cnt[] = 0
x = hash.(1:1000)
@test sort(x; by=incr_identity) == sort(x)
@test cnt[] <= 12999
end

# This testset is at the end of the file because it is slow.
@testset "searchsorted" begin
numTypes = [ Int8, Int16, Int32, Int64, Int128,
Expand Down