Skip to content

Instantly share code, notes, and snippets.

@inv2004
Last active October 24, 2019 23:23
Show Gist options
  • Save inv2004/c1470f407c3b76a5a2d6237e67a023e1 to your computer and use it in GitHub Desktop.
Save inv2004/c1470f407c3b76a5a2d6237e67a023e1 to your computer and use it in GitHub Desktop.
#![feature(duration_as_u128)]
#[macro_use]
extern crate bson;
extern crate mongo_driver;
use std::time::Instant;
use std::sync::Arc;
use mongo_driver::client::{ClientPool, Uri};
const DB: &str = "test_bench";
const TBL: &str = "TEST";
fn _create_indexes(client: &mongodb::Client, tbl: &str) {
// let coll = client.db(DB).collection(tbl);
//
// coll.create_index(doc! {"sequence": 1}, None)
// .unwrap();
//
// coll.create_index(doc! {"time": 1}, None)
// .unwrap();
}
fn init_db() -> mongo_driver::Result<Arc<ClientPool>> {
let pool = ClientPool::new(Uri::new("mongodb://127.0.0.1:27017").unwrap(), None);
Ok(Arc::new(pool))
}
fn bench(pool: &Arc<ClientPool>) {
let doc = doc!{"type" : "done", "order_id" : "a5cce297-3533-4032-917a-98e7cee4820b", "reason" : "canceled", "product_id" : "BTC-USD", "sequence" : 7030956642 as u64, "time" : "2018-09-23T01:12:08.856000Z", "side" : "buy", "price" : "6596.48000000", "remaining_size" : "0.00150000" };
(0..1000).for_each(move |_| {
let client = pool.pop();
let coll = client.get_collection(DB, TBL);
let doc2 = doc.clone();
coll
.insert(&doc2, None)
.unwrap();
});
}
fn main() {
let pool = init_db().unwrap();
let now = Instant::now();
bench(&pool);
let elapsed = now.elapsed();
println!("ms: {}", elapsed.as_millis());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment