You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Local::now() is called 10,000 times in a single thread, it barely takes any time. However, when called in a multithreaded environment, it takes significantly more time. Below is the example code:
fn test_proc()
{
let i=Instant::now();
for _ in 0..10000
{
let v=Local::now();
}
let d=i.elapsed();
println!("time:{}",d.as_millis());
}
fn main()
{
println!("first time");
for _ in 0..1
{
thread::spawn(test_proc);
}
sleep(Duration::from_secs(5));
println!("second time");
for _ in 0..10
{
thread::spawn(test_proc);
}
sleep(Duration::from_secs(5));
}
Output:
first time
time:4
second time
time:362
time:363
time:363
time:365
time:364
time:364
time:365
time:365
time:364
time:365