fn add_duration(ben: &mut Bencher<'_>) { let a = 1.milliseconds(); let b = 1.seconds(); let c = 1.minutes(); let d = 1.hours(); let e = 1.days();
ben.iter(|| Time::MIDNIGHT + a);
ben.iter(|| Time::MIDNIGHT + b);
ben.iter(|| Time::MIDNIGHT + c);
ben.iter(|| Time::MIDNIGHT + d);
ben.iter(|| Time::MIDNIGHT + e);
}
fn add_assign_duration(ben: &mut Bencher<'_>) { let a = 1.milliseconds(); let b = 1.seconds(); let c = 1.minutes(); let d = 1.hours(); let e = 1.days();
iter_batched_ref!(
ben,
|| Time::MIDNIGHT,
[
|time| *time += a,
|time| *time += b,
|time| *time += c,
|time| *time += d,
|time| *time += e,
]
);
}
fn sub_duration(ben: &mut Bencher<'_>) { let a = 1.milliseconds(); let b = 1.seconds(); let c = 1.minutes(); let d = 1.hours(); let e = 1.days();
ben.iter(|| Time::MIDNIGHT - a);
ben.iter(|| Time::MIDNIGHT - b);
ben.iter(|| Time::MIDNIGHT - c);
ben.iter(|| Time::MIDNIGHT - d);
ben.iter(|| Time::MIDNIGHT - e);
}
fn sub_assign_duration(ben: &mut Bencher<'_>) { let a = 1.milliseconds(); let b = 1.seconds(); let c = 1.minutes(); let d = 1.hours(); let e = 1.days();
iter_batched_ref!(
ben,
|| Time::MIDNIGHT,
[
|time| *time -= a,
|time| *time -= b,
|time| *time -= c,
|time| *time -= d,
|time| *time -= e,
]
);
}
fn add_std_duration(ben: &mut Bencher<'_>) { let a = 1.std_milliseconds(); let b = 1.std_seconds(); let c = 1.std_minutes(); let d = 1.std_hours(); let e = 1.std_days();
ben.iter(|| Time::MIDNIGHT + a);
ben.iter(|| Time::MIDNIGHT + b);
ben.iter(|| Time::MIDNIGHT + c);
ben.iter(|| Time::MIDNIGHT + d);
ben.iter(|| Time::MIDNIGHT + e);
}
fn add_assign_std_duration(ben: &mut Bencher<'_>) { let a = 1.std_milliseconds(); let b = 1.std_seconds(); let c = 1.std_minutes(); let d = 1.std_hours(); let e = 1.std_days();
iter_batched_ref!(
ben,
|| Time::MIDNIGHT,
[
|time| *time += a,
|time| *time += b,
|time| *time += c,
|time| *time += d,
|time| *time += e,
]
);
}
fn sub_std_duration(ben: &mut Bencher<'_>) { let a = 1.std_milliseconds(); let b = 1.std_seconds(); let c = 1.std_minutes(); let d = 1.std_hours(); let e = 1.std_days();
ben.iter(|| Time::MIDNIGHT - a);
ben.iter(|| Time::MIDNIGHT - b);
ben.iter(|| Time::MIDNIGHT - c);
ben.iter(|| Time::MIDNIGHT - d);
ben.iter(|| Time::MIDNIGHT - e);
}
fn sub_assign_std_duration(ben: &mut Bencher<'_>) { let a = 1.std_milliseconds(); let b = 1.std_seconds(); let c = 1.std_minutes(); let d = 1.std_hours(); let e = 1.std_days();
iter_batched_ref!(
ben,
|| Time::MIDNIGHT,
[
|time| *time -= a,
|time| *time -= b,
|time| *time -= c,
|time| *time -= d,
|time| *time -= e,
]
);
}
fn sort_align_8(ben: &mut Bencher<'_>) {
ben.iter_batched_ref(
|| { #[repr(C,align(8))] struct Padder {
arr: [Time;4096],
} letmut res = Padder {
arr: [Time::MIDNIGHT;4096]
}; letmut last = Time::MIDNIGHT; letmut last_hour = 0; for t in &mut res.arr {
*t = last;
t.replace_hour(last_hour).expect("failed to replace hour");
last += 997.std_milliseconds();
last_hour = (last_hour + 5) % 24;
}
res.arr.sort_unstable_by_key(|t|
(t.nanosecond(),t.second(),t.minute(),t.hour())
);
res
},
|v| black_box(v).arr.sort_unstable(),
criterion::BatchSize::SmallInput
)
}
fn sort_align_4(ben: &mut Bencher<'_>) {
ben.iter_batched_ref(
|| { #[repr(C,align(8))] struct Padder {
pad: u32,
arr: [Time;4096],
} letmut res = Padder {
pad: 0,
arr: [Time::MIDNIGHT;4096]
}; letmut last = Time::MIDNIGHT; letmut last_hour = 0; for t in &mut res.arr {
*t = last;
t.replace_hour(last_hour).expect("failed to replace hour");
last += 997.std_milliseconds();
last_hour = (last_hour + 5) % 24;
}
res.arr.sort_unstable_by_key(|t|
(t.nanosecond(),t.second(),t.minute(),t.hour())
);
res
},
|v| black_box(v).arr.sort_unstable(),
criterion::BatchSize::SmallInput
)
}
fn duration_until(ben: &mut Bencher<'_>) { let a = black_box(time!(1:02:03.004_005_006)); let b = black_box(time!(4:05:06.007_008_009));
ben.iter(|| black_box(a.duration_until(b)));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.