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

Improve tests and benchmarks for slice::sort and slice::sort_unstable #42882

Merged
merged 2 commits into from Jul 1, 2017
Merged

Improve tests and benchmarks for slice::sort and slice::sort_unstable #42882

merged 2 commits into from Jul 1, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 24, 2017

This PR just hardens the tests and improves benchmarks.
More specifically:

  1. Benchmarks don't generate vectors in Bencher::iter loops, but simply clone pregenerated vectors.
  2. Benchmark *_strings doesn't allocate Strings in Bencher::iter loops, but merely clones a Vec<&str>.
  3. Benchmarks use seeded XorShiftRng to be more consistent.
  4. Additional tests for slice::sort are added, which test sorting on slices with several ascending/descending runs. The implementation identifies such runs so it's a good idea to test that scenario a bit.
  5. More checks are added to run-pass/vector-sort-panic-safe.rs. Sort algorithms copy elements around a lot (merge sort uses an auxilliary buffer and pdqsort copies the pivot onto the stack before partitioning, then writes it back into the slice). If elements that are being sorted are internally mutable and comparison function mutates them, it is important to make sure that sort algorithms always use the latest "versions" of elements. New checks verify that this is true for both slice::sort and slice::sort_unstable.

As a side note, all of those improvements were made as part of the parallel sorts PR in Rayon (nikomatsakis/rayon#379) and now I'm backporting them into libcore/libstd.

r? @alexcrichton

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Jun 24, 2017

📌 Commit 12205f1 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jun 24, 2017

⌛ Testing commit 12205f1 with merge 32091e1b39664ecd81d82276c1ce000e8a5c75b2...

@bors
Copy link
Contributor

bors commented Jun 24, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

Looks like a legitimate failure?

[01:06:00] 
[01:06:00] failures:
[01:06:00] 
[01:06:00] ---- [run-pass] run-pass/vector-sort-panic-safe.rs stdout ----
[01:06:00] 	
[01:06:00] error: test run failed!
[01:06:00] status: exit code: 101
[01:06:00] command: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/remote-test-client run /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/vector-sort-panic-safe.stage2-arm-unknown-linux-gnueabihf
[01:06:00] stdout:
[01:06:00] ------------------------------------------
[01:06:00] uploaded "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/vector-sort-panic-safe.stage2-arm-unknown-linux-gnueabihf", waiting for result
[01:06:00] 
[01:06:00] ------------------------------------------
[01:06:00] stderr:
[01:06:00] ------------------------------------------
[01:06:00] thread 'main' panicked at 'attempt to calculate the remainder with a divisor of zero', /checkout/src/test/run-pass/vector-sort-panic-safe.rs:151
[01:06:00] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:06:00] 
[01:06:00] ------------------------------------------
[01:06:00] 
[01:06:00] thread '[run-pass] run-pass/vector-sort-panic-safe.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2480
[01:06:00] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:06:00] 
[01:06:00] 
[01:06:00] failures:
[01:06:00]     [run-pass] run-pass/vector-sort-panic-safe.rs
[01:06:00] 
[01:06:00] test result: �[31mFAILED�(B�[m. 2696 passed; 1 failed; 9 ignored; 0 measured; 0 filtered out

@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 24, 2017
@ghost ghost mentioned this pull request Jun 25, 2017
@ghost
Copy link
Author

ghost commented Jun 25, 2017

The failure is apparently due to a codegen bug on ARM platforms.

I believe simply moving let mut rng = thread_rng() (here) outside the innermost loop would work around the build failure. Moving that line of code is a good idea anyway, so... can we do that or should we wait until the codegen issue is resolved?

@alexcrichton
Copy link
Member

@stjepang yeah sounds good to me!

@ghost
Copy link
Author

ghost commented Jun 26, 2017

All right, let's see if it works this time...

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jun 26, 2017

📌 Commit 723833f has been approved by alexcrichton

@ghost
Copy link
Author

ghost commented Jun 26, 2017

The new failures are spurious, it seems... three targets were not tested at all (they're marked with ! rather than X). Perhaps retry?

@kennytm
Copy link
Member

kennytm commented Jun 26, 2017

@stjepang Don't worry about the travis-ci/pr failure, it is fine as long as the IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1 one passes.

@arielb1 arielb1 added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2017
@Mark-Simulacrum
Copy link
Member

@bors rollup

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 28, 2017
…ches, r=alexcrichton

Improve tests and benchmarks for slice::sort and slice::sort_unstable

This PR just hardens the tests and improves benchmarks.
More specifically:

1. Benchmarks don't generate vectors in `Bencher::iter` loops, but simply clone pregenerated vectors.
2. Benchmark `*_strings` doesn't allocate Strings in `Bencher::iter` loops, but merely clones a `Vec<&str>`.
3. Benchmarks use seeded `XorShiftRng` to be more consistent.
4. Additional tests for `slice::sort` are added, which test sorting on slices with several ascending/descending runs. The implementation identifies such runs so it's a good idea to test that scenario a bit.
5. More checks are added to `run-pass/vector-sort-panic-safe.rs`. Sort algorithms copy elements around a lot (merge sort uses an auxilliary buffer and pdqsort copies the pivot onto the stack before partitioning, then writes it back into the slice). If elements that are being sorted are internally mutable and comparison function mutates them, it is important to make sure that sort algorithms always use the latest "versions" of elements. New checks verify that this is true for both `slice::sort` and `slice::sort_unstable`.

As a side note, all of those improvements were made as part of the parallel sorts PR in Rayon (nikomatsakis/rayon#379) and now I'm backporting them into libcore/libstd.

r? @alexcrichton
@Mark-Simulacrum
Copy link
Member

@bors r- This failed the rollup, with I think the same failure. Possibly will be fixed after the LLVM update, not sure.

[01:05:40] ---- [run-pass] run-pass/vector-sort-panic-safe.rs stdout ----
[01:05:40]
[01:05:40] error: test run failed!
[01:05:40] status: exit code: 101
[01:05:40] command: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/remote-test-client run /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/vector-sort-panic-safe.stage2-arm-unknown-linux-gnueabihftdout:
[01:05:40] ------------------------------------------
[01:05:40] uploaded "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/vector-sort-panic-safe.stage2-arm-unknown-linux-gnueabihf", waiting for result
[01:05:40]
[01:05:40] ------------------------------------------
[01:05:40] stderr:
[01:05:40] ------------------------------------------
[01:05:40] thread 'main' panicked at 'attempt to calculate the remainder with a divisor of zero', /checkout/src/test/run-pass/vector-sort-panic-safe.rs:152
[01:05:40] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:05:40]
[01:05:40] ------------------------------------------
[01:05:40]
[01:05:40] thread '[run-pass] run-pass/vector-sort-panic-safe.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2479
[01:05:40] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:05:40]
[01:05:40]
[01:05:40] failures:
[01:05:40]     [run-pass] run-pass/vector-sort-panic-safe.rs
[01:05:40]
[01:05:40] test result: FAILED. 2697 passed; 1 failed; 9 ignored; 0 measured; 0 filtered out
[01:05:40]
[01:05:40] thread 'main' panicked at 'Some tests failed', /checkout/src/tools/compiletest/src/main.rs:325

@ghost
Copy link
Author

ghost commented Jun 28, 2017

It will be fixed after the update, yes.

@ghost
Copy link
Author

ghost commented Jun 30, 2017

Ok, LLVM has been updated. Should I rebase now?

@alexcrichton
Copy link
Member

@bors: r+

Nah should still apply cleanly!

@bors
Copy link
Contributor

bors commented Jun 30, 2017

📌 Commit 723833f has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jul 1, 2017

⌛ Testing commit 723833f with merge 05b5797...

bors added a commit that referenced this pull request Jul 1, 2017
…xcrichton

Improve tests and benchmarks for slice::sort and slice::sort_unstable

This PR just hardens the tests and improves benchmarks.
More specifically:

1. Benchmarks don't generate vectors in `Bencher::iter` loops, but simply clone pregenerated vectors.
2. Benchmark `*_strings` doesn't allocate Strings in `Bencher::iter` loops, but merely clones a `Vec<&str>`.
3. Benchmarks use seeded `XorShiftRng` to be more consistent.
4. Additional tests for `slice::sort` are added, which test sorting on slices with several ascending/descending runs. The implementation identifies such runs so it's a good idea to test that scenario a bit.
5. More checks are added to `run-pass/vector-sort-panic-safe.rs`. Sort algorithms copy elements around a lot (merge sort uses an auxilliary buffer and pdqsort copies the pivot onto the stack before partitioning, then writes it back into the slice). If elements that are being sorted are internally mutable and comparison function mutates them, it is important to make sure that sort algorithms always use the latest "versions" of elements. New checks verify that this is true for both `slice::sort` and `slice::sort_unstable`.

As a side note, all of those improvements were made as part of the parallel sorts PR in Rayon (nikomatsakis/rayon#379) and now I'm backporting them into libcore/libstd.

r? @alexcrichton
@bors
Copy link
Contributor

bors commented Jul 1, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 05b5797 to master...

@bors bors merged commit 723833f into rust-lang:master Jul 1, 2017
@ghost ghost deleted the improve-sort-tests-and-benches branch July 1, 2017 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants