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 std::time::{self, SystemTime};
|
||||
|
||||
mod packet;
|
||||
use packet::Packet;
|
||||
use std::time;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@ -22,16 +22,29 @@ async fn main() {
|
||||
let client = Client::with_options(client_options).unwrap();
|
||||
let db = client.database("test");
|
||||
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 mut queries: Vec<std::time::Duration> = vec![];
|
||||
|
||||
for _ in 0..num_queries {
|
||||
let start_time = SystemTime::now();
|
||||
|
||||
loop {
|
||||
collection.insert_one(Packet{
|
||||
time: time::SystemTime::now(),
|
||||
text: format!("Current Unix time: {:?}", time::SystemTime::now().duration_since(time::UNIX_EPOCH).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