mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-07 00:00:09 +02:00
benches: add helper functions for building runtimes (#7260)
This commit is contained in:
+19
-14
@@ -10,10 +10,21 @@ async fn work() -> usize {
|
|||||||
black_box(val)
|
black_box(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn basic_scheduler_spawn(c: &mut Criterion) {
|
fn single_rt() -> tokio::runtime::Runtime {
|
||||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
tokio::runtime::Builder::new_current_thread()
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn multi_rt() -> tokio::runtime::Runtime {
|
||||||
|
tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.worker_threads(1)
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn basic_scheduler_spawn(c: &mut Criterion) {
|
||||||
|
let runtime = single_rt();
|
||||||
|
|
||||||
c.bench_function("basic_scheduler_spawn", |b| {
|
c.bench_function("basic_scheduler_spawn", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
@@ -26,9 +37,7 @@ fn basic_scheduler_spawn(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn basic_scheduler_spawn10(c: &mut Criterion) {
|
fn basic_scheduler_spawn10(c: &mut Criterion) {
|
||||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
let runtime = single_rt();
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
c.bench_function("basic_scheduler_spawn10", |b| {
|
c.bench_function("basic_scheduler_spawn10", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
@@ -46,10 +55,8 @@ fn basic_scheduler_spawn10(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn threaded_scheduler_spawn(c: &mut Criterion) {
|
fn threaded_scheduler_spawn(c: &mut Criterion) {
|
||||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
let runtime = multi_rt();
|
||||||
.worker_threads(1)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
c.bench_function("threaded_scheduler_spawn", |b| {
|
c.bench_function("threaded_scheduler_spawn", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
runtime.block_on(async {
|
runtime.block_on(async {
|
||||||
@@ -61,10 +68,8 @@ fn threaded_scheduler_spawn(c: &mut Criterion) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn threaded_scheduler_spawn10(c: &mut Criterion) {
|
fn threaded_scheduler_spawn10(c: &mut Criterion) {
|
||||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
let runtime = multi_rt();
|
||||||
.worker_threads(1)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
c.bench_function("threaded_scheduler_spawn10", |b| {
|
c.bench_function("threaded_scheduler_spawn10", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
runtime.block_on(async {
|
runtime.block_on(async {
|
||||||
|
|||||||
Reference in New Issue
Block a user