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

Slightly optimize slice::sort #39538

Merged
merged 2 commits into from Feb 5, 2017
Merged

Slightly optimize slice::sort #39538

merged 2 commits into from Feb 5, 2017

Commits on Feb 4, 2017

  1. Slightly optimize slice::sort

    First, get rid of some bound checks.
    
    Second, instead of comparing by ternary `compare` function, use a binary
    function testing whether an element is less than some other element.
    This apparently makes it easier for the compiler to reason about the
    code.
    
    Benchmark:
    
    ```
    name                                        before ns/iter        after ns/iter         diff ns/iter   diff %
    slice::bench::sort_large_ascending          8,969 (8919 MB/s)     7,410 (10796 MB/s)          -1,559  -17.38%
    slice::bench::sort_large_big_ascending      355,640 (3599 MB/s)   359,137 (3564 MB/s)          3,497    0.98%
    slice::bench::sort_large_big_descending     427,112 (2996 MB/s)   424,721 (3013 MB/s)         -2,391   -0.56%
    slice::bench::sort_large_big_random         2,207,799 (579 MB/s)  2,138,804 (598 MB/s)       -68,995   -3.13%
    slice::bench::sort_large_descending         13,694 (5841 MB/s)    13,514 (5919 MB/s)            -180   -1.31%
    slice::bench::sort_large_mostly_ascending   239,697 (333 MB/s)    203,542 (393 MB/s)         -36,155  -15.08%
    slice::bench::sort_large_mostly_descending  270,102 (296 MB/s)    234,263 (341 MB/s)         -35,839  -13.27%
    slice::bench::sort_large_random             513,406 (155 MB/s)    470,084 (170 MB/s)         -43,322   -8.44%
    slice::bench::sort_large_random_expensive   23,650,321 (3 MB/s)   23,675,098 (3 MB/s)         24,777    0.10%
    slice::bench::sort_medium_ascending         143 (5594 MB/s)       132 (6060 MB/s)                -11   -7.69%
    slice::bench::sort_medium_descending        197 (4060 MB/s)       188 (4255 MB/s)                 -9   -4.57%
    slice::bench::sort_medium_random            3,358 (238 MB/s)      3,271 (244 MB/s)               -87   -2.59%
    slice::bench::sort_small_ascending          32 (2500 MB/s)        32 (2500 MB/s)                   0    0.00%
    slice::bench::sort_small_big_ascending      97 (13195 MB/s)       97 (13195 MB/s)                  0    0.00%
    slice::bench::sort_small_big_descending     247 (5182 MB/s)       249 (5140 MB/s)                  2    0.81%
    slice::bench::sort_small_big_random         502 (2549 MB/s)       498 (2570 MB/s)                 -4   -0.80%
    slice::bench::sort_small_descending         55 (1454 MB/s)        61 (1311 MB/s)                   6   10.91%
    slice::bench::sort_small_random             358 (223 MB/s)        356 (224 MB/s)                  -2   -0.56%
    ```
    Stjepan Glavina committed Feb 4, 2017
    Configuration menu
    Copy the full SHA
    a884a6c View commit details
    Browse the repository at this point in the history
  2. Minor fix in the *_expensive benchmark

    Before, the `count` would be copied into the closure and could
    potentially be optimized way. This change ensures it's borrowed by
    closure and finally consumed by `test::black_box`.
    Stjepan Glavina committed Feb 4, 2017
    Configuration menu
    Copy the full SHA
    fa457bf View commit details
    Browse the repository at this point in the history