Skip to content

Commit

Permalink
Use instant instead systemtime (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin authored Oct 12, 2024
1 parent 784497d commit 1c99adb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
8 changes: 4 additions & 4 deletions czkawka_core/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::sync::{atomic, Arc};
use std::thread::{sleep, JoinHandle};
use std::time::{Duration, SystemTime};
use std::time::{Duration, Instant};
use std::{fs, thread};

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

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

progress_send.send(progress_data).expect("Cannot send progress data");
time_since_last_send = SystemTime::now();
time_since_last_send = Instant::now();
}
if !progress_thread_run.load(atomic::Ordering::Relaxed) {
break;
Expand Down
15 changes: 3 additions & 12 deletions czkawka_core/src/similar_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::atomic::Ordering;
use std::time::SystemTime;
use std::time::Instant;
use std::{mem, panic};

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

let start = SystemTime::now();
let start = Instant::now();

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

let end = SystemTime::now();

println!(
"{:?} us {:?} {:?} {}x{}",
end.duration_since(start).expect("Used time backwards").as_micros(),
alg,
filter,
size,
size
);
println!("{:?} us {:?} {:?} {}x{}", start.elapsed().as_micros(), alg, filter, size, size);
}
}
}
Expand Down

0 comments on commit 1c99adb

Please sign in to comment.