]>
git.proxmox.com Git - rustc.git/blob - vendor/rustc-rayon/tests/octillion.rs
3 const OCTILLION
: u128
= 1_000_000_000_000_000_000_000_000_000;
5 /// Produce a parallel iterator for 0u128..10²⁷
6 fn octillion() -> rayon
::range
::Iter
<u128
> {
7 (0..OCTILLION
).into_par_iter()
10 /// Produce a parallel iterator for 0u128..=10²⁷
11 fn octillion_inclusive() -> rayon
::range_inclusive
::Iter
<u128
> {
12 (0..=OCTILLION
).into_par_iter()
15 /// Produce a parallel iterator for 0u128..10²⁷ using `flat_map`
16 fn octillion_flat() -> impl ParallelIterator
<Item
= u128
> {
20 .map(|i
| u64::from(i
) * 1_000_000_000)
25 .map(move |j
| i
+ u64::from(j
))
27 .map(|i
| u128
::from(i
) * 1_000_000_000)
32 .map(move |j
| i
+ u128
::from(j
))
36 // NOTE: `find_first` and `find_last` currently take too long on 32-bit targets,
37 // because the `AtomicUsize` match position has much too limited resolution.
40 #[cfg_attr(not(target_pointer_width = "64"), ignore)]
41 fn find_first_octillion() {
42 let x
= octillion().find_first(|_
| true);
43 assert_eq
!(x
, Some(0));
47 #[cfg_attr(not(target_pointer_width = "64"), ignore)]
48 fn find_first_octillion_inclusive() {
49 let x
= octillion_inclusive().find_first(|_
| true);
50 assert_eq
!(x
, Some(0));
54 #[cfg_attr(not(target_pointer_width = "64"), ignore)]
55 fn find_first_octillion_flat() {
56 let x
= octillion_flat().find_first(|_
| true);
57 assert_eq
!(x
, Some(0));
60 fn two_threads
<F
: Send
+ FnOnce() -> R
, R
: Send
>(f
: F
) -> R
{
61 // FIXME: If we don't use at least two threads, then we end up walking
62 // through the entire iterator sequentially, without the benefit of any
63 // short-circuiting. We probably don't want testing to wait that long. ;)
64 let builder
= rayon
::ThreadPoolBuilder
::new().num_threads(2);
65 let pool
= builder
.build().unwrap();
71 #[cfg_attr(not(target_pointer_width = "64"), ignore)]
72 fn find_last_octillion() {
73 // It would be nice if `find_last` could prioritize the later splits,
74 // basically flipping the `join` args, without needing indexed `rev`.
75 // (or could we have an unindexed `rev`?)
76 let x
= two_threads(|| octillion().find_last(|_
| true));
77 assert_eq
!(x
, Some(OCTILLION
- 1));
81 #[cfg_attr(not(target_pointer_width = "64"), ignore)]
82 fn find_last_octillion_inclusive() {
83 let x
= two_threads(|| octillion_inclusive().find_last(|_
| true));
84 assert_eq
!(x
, Some(OCTILLION
));
88 #[cfg_attr(not(target_pointer_width = "64"), ignore)]
89 fn find_last_octillion_flat() {
90 let x
= two_threads(|| octillion_flat().find_last(|_
| true));
91 assert_eq
!(x
, Some(OCTILLION
- 1));
95 fn find_any_octillion() {
96 let x
= two_threads(|| octillion().find_any(|x
| *x
> OCTILLION
/ 2));
101 fn find_any_octillion_flat() {
102 let x
= two_threads(|| octillion_flat().find_any(|x
| *x
> OCTILLION
/ 2));
103 assert
!(x
.is_some());
107 fn filter_find_any_octillion() {
108 let x
= two_threads(|| {
110 .filter(|x
| *x
> OCTILLION
/ 2)
113 assert
!(x
.is_some());
117 fn filter_find_any_octillion_flat() {
118 let x
= two_threads(|| {
120 .filter(|x
| *x
> OCTILLION
/ 2)
123 assert
!(x
.is_some());
127 fn fold_find_any_octillion_flat() {
128 let x
= two_threads(|| octillion_flat().fold(|| (), |_
, _
| ()).find_any(|_
| true));
129 assert
!(x
.is_some());