Updated program to record query durations
This commit is contained in:
parent
5b8e7de9f1
commit
7ec01a8717
21
src/main.rs
21
src/main.rs
@ -1,8 +1,8 @@
|
|||||||
use core::panic;
|
|
||||||
use mongodb::{Client, options::{ClientOptions, Credential}};
|
use mongodb::{Client, options::{ClientOptions, Credential}};
|
||||||
|
use std::time::{self, SystemTime};
|
||||||
|
|
||||||
mod packet;
|
mod packet;
|
||||||
use packet::Packet;
|
use packet::Packet;
|
||||||
use std::time;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@ -22,16 +22,29 @@ async fn main() {
|
|||||||
let client = Client::with_options(client_options).unwrap();
|
let client = Client::with_options(client_options).unwrap();
|
||||||
let db = client.database("test");
|
let db = client.database("test");
|
||||||
match db.create_collection("test", None).await {
|
match db.create_collection("test", None).await {
|
||||||
Err(_) => panic!("ERROR: incorrect usage"),
|
Err(_) => {
|
||||||
|
db.collection::<Packet>("test").drop(None).await.unwrap();
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const num_queries: u32 = 5_000;
|
||||||
let collection = db.collection::<Packet>("test");
|
let collection = db.collection::<Packet>("test");
|
||||||
|
let mut queries: Vec<std::time::Duration> = vec![];
|
||||||
|
|
||||||
loop {
|
for _ in 0..num_queries {
|
||||||
|
let start_time = SystemTime::now();
|
||||||
|
|
||||||
collection.insert_one(Packet{
|
collection.insert_one(Packet{
|
||||||
time: time::SystemTime::now(),
|
time: time::SystemTime::now(),
|
||||||
text: format!("Current Unix time: {:?}", time::SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap())
|
text: format!("Current Unix time: {:?}", time::SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap())
|
||||||
}, None).await.unwrap();
|
}, None).await.unwrap();
|
||||||
|
|
||||||
|
let duration = time::SystemTime::now().duration_since(start_time).unwrap();
|
||||||
|
queries.push(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i, duration) in queries.iter().enumerate() {
|
||||||
|
println!("{}: {}.{} milliseconds", i, duration.as_millis(), duration.as_micros());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user