Skip to content

Commit 75f88a9

Browse files
committed
use start time instead of end time; sort results in csv
1 parent 8589af5 commit 75f88a9

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ fn main() -> Result<()> {
114114
});
115115

116116
let mut res = res?;
117+
res.sort_by_key(|r| r.timestamp);
117118

118119
if let Some(path) = args.output {
119120
let f = get_output_file(&path)?;
@@ -123,7 +124,7 @@ fn main() -> Result<()> {
123124
if args.csv {
124125
write_csv(io::stdout(), &res)?;
125126
} else if !args.silent {
126-
res.sort();
127+
res.sort_by_key(|r| r.took);
127128
print_stats(&res);
128129
}
129130

@@ -170,8 +171,8 @@ fn print_stats(res: &[Response]) {
170171

171172
let n = res.len() as f64;
172173

173-
let min = res.iter().min();
174-
let max = res.iter().max();
174+
let min = res.iter().min_by_key(|r| r.took);
175+
let max = res.iter().max_by_key(|r| r.took);
175176

176177
let min_t = min.unwrap().took;
177178
let min_s = min.unwrap().status;

src/request.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@ use reqwest::{
77
};
88
use std::time::{Duration, Instant};
99

10-
#[derive(Debug, PartialEq, Eq)]
10+
#[derive(Debug)]
1111
pub struct Response {
1212
pub status: StatusCode,
1313
pub took: Duration,
1414
pub timestamp: DateTime<Utc>,
1515
}
1616

17-
impl Ord for Response {
18-
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
19-
self.took.cmp(&other.took)
20-
}
21-
}
22-
23-
impl PartialOrd for Response {
24-
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
25-
self.took.partial_cmp(&other.took)
26-
}
27-
}
28-
2917
pub struct Client {
3018
client: reqwest::blocking::Client,
3119
url: Url,
@@ -53,14 +41,15 @@ impl Client {
5341
pub fn send(&self) -> Result<Response> {
5442
let req = self.create_request();
5543

44+
let started = Utc::now();
5645
let before = Instant::now();
5746
let res = self.client.execute(req)?;
5847
let after = Instant::now();
5948

6049
Ok(Response {
6150
status: res.status(),
6251
took: after - before,
63-
timestamp: Utc::now(),
52+
timestamp: started,
6453
})
6554
}
6655

0 commit comments

Comments
 (0)