[−][src]Crate out
Provides functionality to get the n
largest items from slices and iterators.
let mut v = [-5, 4, 1, -3, 2]; let max = out::max(&mut v, 3); assert_eq!(max, [1, 2, 4]);
This library can provide significant performance increase compared to sorting or
converting to a heap when n
is relatively small compared to the length of the slice or iterator.
Benchmarks
n = 100
, len = 1_000_000
:
openSUSE Tumbleweed, i7-5820K @ 3.30GHz, and 16GiB RAM:
binary_heap ... bench: 6,599,355 ns/iter (+/- 84,674)
max ... bench: 669,726 ns/iter (+/- 13,595)
max_unstable ... bench: 635,435 ns/iter (+/- 9,683)
sort ... bench: 62,585,547 ns/iter (+/- 1,361,258)
sort_unstable ... bench: 34,595,265 ns/iter (+/- 739,255)
openSUSE Leap 15.0, i7-7700 @ 3.60GHz, and 32GiB RAM:
binary_heap ... bench: 5,521,422 ns/iter (+/- 124,780)
max ... bench: 653,428 ns/iter (+/- 13,913)
max_unstable ... bench: 524,200 ns/iter (+/- 61,033)
sort ... bench: 41,428,917 ns/iter (+/- 486,681)
sort_unstable ... bench: 26,124,912 ns/iter (+/- 439,856)
Windows 10 Pro, i7-5820K @ 3.30GHz, and 16GiB RAM:
binary_heap ... bench: 8,550,850 ns/iter (+/- 1,118,958)
max ... bench: 2,282,062 ns/iter (+/- 564,063)
max_unstable ... bench: 2,179,817 ns/iter (+/- 741,751)
sort ... bench: 67,915,490 ns/iter (+/- 5,252,960)
sort_unstable ... bench: 34,022,120 ns/iter (+/- 3,745,490)
Functions
max | Get the |
max_by | Get the |
max_by_cached_key | Get the |
max_by_key | Get the |
max_from_iter | Get the |
max_from_iter_by | Get the |
max_from_iter_by_key | Get the |
max_from_iter_unstable | Get the |
max_from_iter_unstable_by | Get the |
max_from_iter_unstable_by_key | Get the |
max_unstable | Get the |
max_unstable_by | Get the |
max_unstable_by_key | Get the |