Rust: tokio,异步代码与运行速度初探
几个问题: 1、同样的一段代码,放在异步中,运行速度会如何? 2、什么情况下异步并没有改变运行速度? 3、如何提升异步的速度? toml: [dependencies] tokio = { version = "1", features = ["full"] } futures = "0.3.4" 代码: use std::time::{Duration, Instant}; use std::thread; use tokio::time; const N:i32 =1000000; struct bar{ price :f64, code: Option<String>, close: f64, open:f64, high:f64, low:f64, } impl bar{ fn default()->Self{ bar{ price:0.0, code :Some(String::from("I AM NULL")), close:0.0, open:0.0, high:0.0, low:0.0, } } fn push_vec(n:i32)->Vec<Self>{ let mut v = vec![]; for _ in 0..N{ v.push(bar::default()); } v } } fn hello(){ let v = bar::push_vec(N);