feat: Replace the elapsed dependency by std::time::Instant

This commit is contained in:
Clément Renault 2019-02-16 20:44:16 +01:00
parent bddb37e44f
commit 264fffa826
No known key found for this signature in database
GPG key ID: 0151CDAB43460DAE
6 changed files with 56 additions and 57 deletions

View file

@ -4,8 +4,6 @@ mod shared_data;
use std::slice::from_raw_parts;
use std::mem::size_of;
use std::ops::Deref;
use std::sync::Arc;
pub use self::doc_ids::DocIds;
pub use self::doc_indexes::{DocIndexes, DocIndexesBuilder};

View file

@ -1,8 +1,7 @@
use crate::DocumentId;
use crate::database::schema::SchemaAttr;
use std::sync::Arc;
use std::time::Instant;
use std::error::Error;
use std::ffi::OsStr;
use std::sync::Arc;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
@ -17,8 +16,10 @@ use lockfree::map::Map;
use hashbrown::HashMap;
use log::{info, error, warn};
use crate::database::schema::SchemaAttr;
use crate::shared_data_cursor::FromSharedDataCursor;
use crate::write_to_bytes::WriteToBytes;
use crate::DocumentId;
pub use self::document_key::{DocumentKey, DocumentKeyAttr};
pub use self::view::{DatabaseView, DocumentIter};
@ -56,25 +57,25 @@ where D: Deref<Target=DB>
{
use self::update::ReadIndexEvent::{self, *};
let (elapsed, vector) = elapsed::measure_time(|| snapshot.get(DATA_INDEX));
info!("loading index from kv-store took {}", elapsed);
let start = Instant::now();
let vector = snapshot.get(DATA_INDEX)?;
info!("loading index from kv-store took {:.2?}", start.elapsed());
match vector? {
match vector {
Some(vector) => {
let start = Instant::now();
let bytes = vector.as_ref().to_vec();
let size = SizeFormatterBinary::new(bytes.len() as u64);
info!("index size is {}B", size);
info!("index size is {}B", SizeFormatterBinary::new(bytes.len() as u64));
let (elapsed, result) = elapsed::measure_time(|| {
match ReadIndexEvent::from_bytes(bytes.to_vec())? {
RemovedDocuments(_) => unreachable!("BUG: Must not extract a RemovedDocuments"),
UpdatedDocuments(index) => Ok(index),
}
});
let index = match ReadIndexEvent::from_bytes(bytes)? {
RemovedDocuments(_) => panic!("BUG: RemovedDocument event retrieved"),
UpdatedDocuments(index) => index,
};
info!("loading index from bytes took {}", elapsed);
info!("loading index from bytes took {:.2?}", start.elapsed());
result
Ok(index)
},
None => Ok(Index::default()),
}
@ -85,25 +86,25 @@ where D: Deref<Target=DB>,
{
use self::update::ReadRankedMapEvent::{self, *};
let (elapsed, vector) = elapsed::measure_time(|| snapshot.get(DATA_RANKED_MAP));
info!("loading ranked map from kv-store took {}", elapsed);
let start = Instant::now();
let vector = snapshot.get(DATA_RANKED_MAP)?;
info!("loading ranked map from kv-store took {:.2?}", start.elapsed());
match vector? {
match vector {
Some(vector) => {
let start = Instant::now();
let bytes = vector.as_ref().to_vec();
let size = SizeFormatterBinary::new(bytes.len() as u64);
info!("ranked map size is {}B", size);
info!("ranked map size is {}B", SizeFormatterBinary::new(bytes.len() as u64));
let (elapsed, result) = elapsed::measure_time(|| {
match ReadRankedMapEvent::from_bytes(bytes.to_vec())? {
RemovedDocuments(_) => unreachable!("BUG: Must not extract a RemovedDocuments"),
UpdatedDocuments(ranked_map) => Ok(ranked_map),
}
});
let ranked_map = match ReadRankedMapEvent::from_bytes(bytes)? {
RemovedDocuments(_) => panic!("BUG: RemovedDocument event retrieved"),
UpdatedDocuments(ranked_map) => ranked_map,
};
info!("loading ranked map from bytes took {}", elapsed);
info!("loading ranked map from bytes took {:.2?}", start.elapsed());
result
Ok(ranked_map)
},
None => Ok(RankedMap::new()),
}

View file

@ -1,12 +1,12 @@
use std::{cmp, mem, vec, str, char};
use std::ops::{Deref, Range};
use std::time::Instant;
use std::error::Error;
use std::hash::Hash;
use std::rc::Rc;
use rayon::slice::ParallelSliceMut;
use slice_group_by::GroupByMut;
use elapsed::measure_time;
use hashbrown::HashMap;
use fst::Streamer;
use rocksdb::DB;
@ -143,8 +143,9 @@ where D: Deref<Target=DB>,
return builder.query(query, range);
}
let (elapsed, mut documents) = measure_time(|| self.query_all(query));
info!("query_all took {}", elapsed);
let start = Instant::now();
let mut documents = self.query_all(query);
info!("query_all took {:.2?}", start.elapsed());
let mut groups = vec![documents.as_mut_slice()];
@ -163,10 +164,9 @@ where D: Deref<Target=DB>,
continue;
}
let (elapsed, _) = measure_time(|| {
group.par_sort_unstable_by(|a, b| criterion.evaluate(a, b));
});
info!("criterion {} sort took {}", ci, elapsed);
let start = Instant::now();
group.par_sort_unstable_by(|a, b| criterion.evaluate(a, b));
info!("criterion {} sort took {:.2?}", ci, start.elapsed());
for group in group.binary_group_by_mut(|a, b| criterion.eq(a, b)) {
documents_seen += group.len();
@ -214,8 +214,9 @@ where D: Deref<Target=DB>,
K: Hash + Eq,
{
pub fn query(self, query: &str, range: Range<usize>) -> Vec<Document> {
let (elapsed, mut documents) = measure_time(|| self.inner.query_all(query));
info!("query_all took {}", elapsed);
let start = Instant::now();
let mut documents = self.inner.query_all(query);
info!("query_all took {:.2?}", start.elapsed());
let mut groups = vec![documents.as_mut_slice()];
let mut key_cache = HashMap::new();
@ -244,10 +245,9 @@ where D: Deref<Target=DB>,
continue;
}
let (elapsed, _) = measure_time(|| {
group.par_sort_unstable_by(|a, b| criterion.evaluate(a, b));
});
info!("criterion {} sort took {}", ci, elapsed);
let start = Instant::now();
group.par_sort_unstable_by(|a, b| criterion.evaluate(a, b));
info!("criterion {} sort took {:.2?}", ci, start.elapsed());
for group in group.binary_group_by_mut(|a, b| criterion.eq(a, b)) {
// we must compute the real distinguished len of this sub-group