fix unit test for bench. remove scoref64 feature. fixed test for lz4 feature.

This commit is contained in:
Paul Masurel
2020-09-08 07:35:00 +09:00
parent 73024a8af3
commit 4ce9517a82
7 changed files with 20 additions and 24 deletions

View File

@@ -79,7 +79,6 @@ lz4-compression = ["lz4"]
failpoints = ["fail/failpoints"]
unstable = [] # useful for benches.
wasm-bindgen = ["uuid/wasm-bindgen"]
scoref64 = [] # scores are f64 instead of f32. was introduced to debug blockwand.
[workspace]
members = ["query-grammar"]

View File

@@ -271,7 +271,11 @@ mod tests {
let mut vec = Vec::new();
let footer_proxy = FooterProxy::new(&mut vec);
assert!(footer_proxy.terminate().is_ok());
assert_eq!(vec.len(), 167);
if crate::store::COMPRESSION == "lz4" {
assert_eq!(vec.len(), 158);
} else {
assert_eq!(vec.len(), 167);
}
let footer = Footer::deserialize(&mut &vec[..]).unwrap();
assert!(matches!(
footer.versioned_footer,

View File

@@ -245,18 +245,6 @@ pub type DocId = u32;
/// with opstamp `n+1`.
pub type Opstamp = u64;
/// A Score that represents the relevance of the document to the query
///
/// This is modelled internally as a `f64`, because tantivy was compiled with the `scoref64`
/// feature. The larger the number, the more relevant the document is to the search query.
#[cfg(feature = "scoref64")]
pub type Score = f64;
/// A Score that represents the relevance of the document to the query
///
/// This is modelled internally as a `f32`. The larger the number, the more relevant
/// the document to the search query.
#[cfg(not(feature = "scoref64"))]
pub type Score = f32;
/// A `SegmentLocalId` identifies a segment.

View File

@@ -310,6 +310,7 @@ pub mod tests {
mod bench {
use super::*;
use crate::TERMINATED;
use rand::rngs::StdRng;
use rand::Rng;
use rand::SeedableRng;
@@ -340,7 +341,7 @@ mod bench {
let mut encoder = BlockEncoder::new();
let data = generate_array(COMPRESSION_BLOCK_SIZE, 0.1);
let (num_bits, compressed) = encoder.compress_block_sorted(&data, 0u32);
let mut decoder = BlockDecoder::new();
let mut decoder = BlockDecoder::default();
b.iter(|| {
decoder.uncompress_block_sorted(compressed, 0u32, num_bits);
});
@@ -375,9 +376,9 @@ mod bench {
let mut encoder = BlockEncoder::new();
let data = generate_array(NUM_INTS_BENCH_VINT, 0.001);
let compressed = encoder.compress_vint_sorted(&data, 0u32);
let mut decoder = BlockDecoder::new();
let mut decoder = BlockDecoder::default();
b.iter(|| {
decoder.uncompress_vint_sorted(compressed, 0u32, NUM_INTS_BENCH_VINT);
decoder.uncompress_vint_sorted(compressed, 0u32, NUM_INTS_BENCH_VINT, TERMINATED);
});
}
}

View File

@@ -727,7 +727,7 @@ mod bench {
let mut s = 0u32;
while segment_postings.doc() != TERMINATED {
s += (segment_postings.doc() & n) % 1024;
segment_postings.advance()
segment_postings.advance();
}
s
});

View File

@@ -114,7 +114,7 @@ impl SegmentPostings {
.iter()
.map(|&fieldnorm| fieldnorm as u64)
.sum::<u64>();
total_num_tokens as Score / fieldnorms.len() as f32
total_num_tokens as Score / fieldnorms.len() as Score
})
.unwrap_or(0.0);
let mut postings_serializer = PostingsSerializer::new(

View File

@@ -398,9 +398,9 @@ mod bench {
use crate::query::score_combiner::DoNothingCombiner;
use crate::query::{ConstScorer, Union, VecDocSet};
use crate::tests;
use crate::DocId;
use crate::DocSet;
use crate::{tests, TERMINATED};
use test::Bencher;
#[bench]
@@ -414,10 +414,12 @@ mod bench {
union_docset
.iter()
.map(|doc_ids| VecDocSet::from(doc_ids.clone()))
.map(ConstScorer::new)
.map(|docset| ConstScorer::new(docset, 1.0))
.collect::<Vec<_>>(),
);
while v.advance() {}
while v.doc() != TERMINATED {
v.advance();
}
});
}
#[bench]
@@ -432,10 +434,12 @@ mod bench {
union_docset
.iter()
.map(|doc_ids| VecDocSet::from(doc_ids.clone()))
.map(ConstScorer::new)
.map(|docset| ConstScorer::new(docset, 1.0))
.collect::<Vec<_>>(),
);
while v.advance() {}
while v.doc() != TERMINATED {
v.advance();
}
});
}
}