Skip to content

Commit

Permalink
add high and low priority flags to lepton utility for more reliable b…
Browse files Browse the repository at this point in the history
…enchmarking (#66)

* add high and low priority flags

* add comments and force priority on main thread as well

* set windows version cores

* only add in windows
  • Loading branch information
mcroomp authored Apr 19, 2024
1 parent 983873c commit 5ac1daf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 25 deletions.
77 changes: 52 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rayon = "1.10"

[target.'cfg(windows)'.dependencies]
cpu-time = "1.0"
thread-priority = "0.16"

[dev-dependencies]
rstest = "0.18"
Expand Down
35 changes: 35 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use lepton_jpeg::metrics::CpuTimeMeasure;
use log::info;
use simple_logger::SimpleLogger;
use structs::lepton_format::read_jpeg;
use thread_priority::{set_current_thread_priority, ThreadPriority, WinAPIThreadPriority};

use std::{
env,
Expand Down Expand Up @@ -73,6 +74,40 @@ fn main_with_result() -> anyhow::Result<()> {
dump = true;
} else if args[i] == "-all" {
all = true;
} else if args[i] == "-highpriority" {
// used to force to run on p-cores, make sure this and
// any threadpool threads are set to the high priority

#[cfg(target_os = "windows")]
{
let priority = ThreadPriority::Os(WinAPIThreadPriority::TimeCritical.into());

set_current_thread_priority(priority).unwrap();

let b = rayon::ThreadPoolBuilder::new();
b.start_handler(move |_| {
set_current_thread_priority(priority).unwrap();
})
.build_global()
.unwrap();
}
} else if args[i] == "-lowpriority" {
// used to force to run on e-cores, make sure this and
// any threadpool threads are set to the high priority

#[cfg(target_os = "windows")]
{
let priority = ThreadPriority::Os(WinAPIThreadPriority::Idle.into());

set_current_thread_priority(priority).unwrap();

let b = rayon::ThreadPoolBuilder::new();
b.start_handler(move |_| {
set_current_thread_priority(priority).unwrap();
})
.build_global()
.unwrap();
}
} else if args[i] == "-overwrite" {
overwrite = true;
} else if args[i] == "-noprogressive" {
Expand Down

0 comments on commit 5ac1daf

Please sign in to comment.