Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix millisecond conversions for Request #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ pub trait Runnable {
#[derive(Clone)]
pub struct Report {
pub name: String,
pub duration: f64,
pub duration_ms: f64,
pub status: u16,
}

impl fmt::Debug for Report {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\n- name: {}\n duration: {}\n", self.name, self.duration)
write!(f, "\n- name: {}\n duration: {}\n", self.name, self.duration_ms)
}
}

impl fmt::Display for Report {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\n- name: {}\n duration: {}\n status: {}\n", self.name, self.duration, self.status)
write!(f, "\n- name: {}\n duration: {}\n status: {}\n", self.name, self.duration_ms, self.status)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/actions/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ impl Runnable for Request {
match res {
None => reports.push(Report {
name: self.name.to_owned(),
duration: duration_ms,
duration_ms,
status: 520u16,
}),
Some(response) => {
let status = response.status().as_u16();

reports.push(Report {
name: self.name.to_owned(),
duration: duration_ms,
duration_ms,
status,
});

Expand Down
2 changes: 1 addition & 1 deletion src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn compare(list_reports: &[Vec<Report>], filepath: &str, threshold: &str) ->
for report in list_reports {
for (i, report_item) in report.iter().enumerate() {
let recorded_duration = items[i]["duration"].as_f64().unwrap();
let delta_ms = report_item.duration - recorded_duration;
let delta_ms = report_item.duration_ms - recorded_duration;

if delta_ms > threshold_value {
println!("{:width$} is {}{} slower than before", report_item.name.green(), delta_ms.round().to_string().red(), "ms".red(), width = 25);
Expand Down
42 changes: 21 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ struct DrillStats {
}

impl DrillStats {
fn mean_duration(&self) -> f64 {
self.hist.mean() / 1_000.0
fn mean_duration_ms(&self) -> f64 {
self.hist.mean()
}
fn median_duration(&self) -> f64 {
self.hist.value_at_quantile(0.5) as f64 / 1_000.0
fn median_duration_ms(&self) -> f64 {
self.hist.value_at_quantile(0.5) as f64
}
fn stdev_duration(&self) -> f64 {
self.hist.stdev() / 1_000.0
fn stdev_duration_ms(&self) -> f64 {
self.hist.stdev()
}
fn value_at_quantile(&self, quantile: f64) -> f64 {
self.hist.value_at_quantile(quantile) as f64 / 1_000.0
fn value_at_quantile_ms(&self, quantile: f64) -> f64 {
self.hist.value_at_quantile(quantile) as f64
}
}

Expand All @@ -113,7 +113,7 @@ fn compute_stats(sub_reports: &[Report]) -> DrillStats {
}

for r in sub_reports.iter() {
hist += (r.duration * 1_000.0) as u64;
hist += r.duration_ms as u64;
}

let total_requests = sub_reports.len();
Expand Down Expand Up @@ -154,12 +154,12 @@ fn show_stats(list_reports: &[Vec<Report>], stats_option: bool, nanosec: bool, d
println!("{:width$} {:width2$} {}", name.green(), "Total requests".yellow(), substats.total_requests.to_string().purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Successful requests".yellow(), substats.successful_requests.to_string().purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Failed requests".yellow(), substats.failed_requests.to_string().purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Median time per request".yellow(), format_time(substats.median_duration(), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Average time per request".yellow(), format_time(substats.mean_duration(), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Sample standard deviation".yellow(), format_time(substats.stdev_duration(), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "99.0'th percentile".yellow(), format_time(substats.value_at_quantile(0.99), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "99.5'th percentile".yellow(), format_time(substats.value_at_quantile(0.995), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "99.9'th percentile".yellow(), format_time(substats.value_at_quantile(0.999), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Median time per request".yellow(), format_time(substats.median_duration_ms(), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Average time per request".yellow(), format_time(substats.mean_duration_ms(), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "Sample standard deviation".yellow(), format_time(substats.stdev_duration_ms(), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "99.0'th percentile".yellow(), format_time(substats.value_at_quantile_ms(0.99), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "99.5'th percentile".yellow(), format_time(substats.value_at_quantile_ms(0.995), nanosec).purple(), width = 25, width2 = 25);
println!("{:width$} {:width2$} {}", name.green(), "99.9'th percentile".yellow(), format_time(substats.value_at_quantile_ms(0.999), nanosec).purple(), width = 25, width2 = 25);
}

// compute global stats
Expand All @@ -173,12 +173,12 @@ fn show_stats(list_reports: &[Vec<Report>], stats_option: bool, nanosec: bool, d
println!("{:width2$} {}", "Successful requests".yellow(), global_stats.successful_requests.to_string().purple(), width2 = 25);
println!("{:width2$} {}", "Failed requests".yellow(), global_stats.failed_requests.to_string().purple(), width2 = 25);
println!("{:width2$} {} {}", "Requests per second".yellow(), format!("{:.2}", requests_per_second).purple(), "[#/sec]".purple(), width2 = 25);
println!("{:width2$} {}", "Median time per request".yellow(), format_time(global_stats.median_duration(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Average time per request".yellow(), format_time(global_stats.mean_duration(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Sample standard deviation".yellow(), format_time(global_stats.stdev_duration(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "99.0'th percentile".yellow(), format_time(global_stats.value_at_quantile(0.99), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "99.5'th percentile".yellow(), format_time(global_stats.value_at_quantile(0.995), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "99.9'th percentile".yellow(), format_time(global_stats.value_at_quantile(0.999), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Median time per request".yellow(), format_time(global_stats.median_duration_ms(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Average time per request".yellow(), format_time(global_stats.mean_duration_ms(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "Sample standard deviation".yellow(), format_time(global_stats.stdev_duration_ms(), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "99.0'th percentile".yellow(), format_time(global_stats.value_at_quantile_ms(0.99), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "99.5'th percentile".yellow(), format_time(global_stats.value_at_quantile_ms(0.995), nanosec).purple(), width2 = 25);
println!("{:width2$} {}", "99.9'th percentile".yellow(), format_time(global_stats.value_at_quantile_ms(0.999), nanosec).purple(), width2 = 25);
}

fn compare_benchmark(list_reports: &[Vec<Report>], compare_path_option: Option<&str>, threshold_option: Option<&str>) {
Expand Down