Skip to content

Commit 1c99adb

Browse files
authored
Use instant instead systemtime (#1369)
1 parent 784497d commit 1c99adb

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

czkawka_core/src/common.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::sync::atomic::{AtomicBool, AtomicUsize};
66
use std::sync::{atomic, Arc};
77
use std::thread::{sleep, JoinHandle};
8-
use std::time::{Duration, SystemTime};
8+
use std::time::{Duration, Instant};
99
use std::{fs, thread};
1010

1111
use crossbeam_channel::Sender;
@@ -529,10 +529,10 @@ pub fn prepare_thread_handler_common(
529529
let atomic_counter = atomic_counter.clone();
530530
thread::spawn(move || {
531531
// Use earlier time, to send immediately first message
532-
let mut time_since_last_send = SystemTime::now() - Duration::from_secs(10u64);
532+
let mut time_since_last_send = Instant::now().checked_sub(Duration::from_secs(10u64)).unwrap();
533533

534534
loop {
535-
if time_since_last_send.elapsed().expect("Cannot count time backwards").as_millis() > SEND_PROGRESS_DATA_TIME_BETWEEN as u128 {
535+
if time_since_last_send.elapsed().as_millis() > SEND_PROGRESS_DATA_TIME_BETWEEN as u128 {
536536
let progress_data = ProgressData {
537537
sstage,
538538
checking_method,
@@ -546,7 +546,7 @@ pub fn prepare_thread_handler_common(
546546
progress_data.validate();
547547

548548
progress_send.send(progress_data).expect("Cannot send progress data");
549-
time_since_last_send = SystemTime::now();
549+
time_since_last_send = Instant::now();
550550
}
551551
if !progress_thread_run.load(atomic::Ordering::Relaxed) {
552552
break;

czkawka_core/src/similar_images.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
22
use std::io::Write;
33
use std::path::{Path, PathBuf};
44
use std::sync::atomic::Ordering;
5-
use std::time::SystemTime;
5+
use std::time::Instant;
66
use std::{mem, panic};
77

88
use bk_tree::BKTree;
@@ -890,21 +890,12 @@ pub fn test_image_conversion_speed() {
890890
for size in [8, 16, 32, 64] {
891891
let hasher_config = HasherConfig::new().hash_alg(alg).resize_filter(filter).hash_size(size, size);
892892

893-
let start = SystemTime::now();
893+
let start = Instant::now();
894894

895895
let hasher = hasher_config.to_hasher();
896896
let _hash = hasher.hash_image(&img_open);
897897

898-
let end = SystemTime::now();
899-
900-
println!(
901-
"{:?} us {:?} {:?} {}x{}",
902-
end.duration_since(start).expect("Used time backwards").as_micros(),
903-
alg,
904-
filter,
905-
size,
906-
size
907-
);
898+
println!("{:?} us {:?} {:?} {}x{}", start.elapsed().as_micros(), alg, filter, size, size);
908899
}
909900
}
910901
}

0 commit comments

Comments
 (0)