Skip to content

Commit

Permalink
Arena Unsafecell index
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Aug 1, 2021
1 parent 7e3714b commit 038c28d
Show file tree
Hide file tree
Showing 9 changed files with 883 additions and 811 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ categories = ["text-processing"]
exclude = [".github/**", ".gitignore", ".rustfmt.toml"]

[dependencies]
ghost-cell = "0.2.2"
typed-arena = "2.0.1"

[dev-dependencies]
Expand All @@ -26,4 +25,9 @@ criterion = {version ="0.3" , features = ["html_reports"]}

[[bench]]
name = "test_benchmark"
harness = false
harness = false


[profile.dev]
opt-level = 0
debug = true
34 changes: 28 additions & 6 deletions benches/test_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::cell::UnsafeCell;

use criterion::{criterion_group, criterion_main, Criterion};
use probly_search::index::{add_document_to_index, create_index, Index};
use probly_search::index::{
add_document_to_index, create_index, create_index_arenas, Index, IndexArenas,
};

criterion_group!(benches, test_speed);
criterion_main!(benches);
Expand Down Expand Up @@ -39,7 +43,10 @@ pub fn test_speed(c: &mut Criterion) {
}

c.bench_function("add_100k_docs", |b| {
let mut idx: Index<usize> = create_index(1);
let index_arenas = create_index_arenas();
let mut index = create_index(1, &index_arenas);

//let x: UnsafeCell<&mut IndexBase<usize>> = UnsafeCell::new(&mut index);
let mut random_strings: Vec<String> = Vec::new();
for _ in 1..100000 {
let mut new_rand = generate_string(0, 4);
Expand All @@ -49,20 +56,35 @@ pub fn test_speed(c: &mut Criterion) {
}
// whatever you want to do
let extractor = [title_extract_x as fn(&_) -> Option<&str>];
b.iter(|| add_all_documents(&mut idx, &extractor, &&random_strings));
b.iter(|| add_all_documents(&mut index, &index_arenas, &extractor, &&random_strings));
});
}

fn add_all_documents(
mut idx: &mut Index<usize>,
fn add_all_documents<'arena>(
//basex: &UnsafeCell<&'arena mut IndexBase<'arena, usize>>,
mut index: &mut Index<'arena, usize>,
index_arenas: &'arena IndexArenas<'arena, usize>,
extractor: &[fn(&DocX) -> Option<&str>],
random_strings: &Vec<String>,
) {
//let mut base = unsafe { basex.get().read() };
for (i, s) in random_strings.iter().enumerate() {
let d = DocX {
id: i,
title: s.to_owned(),
};
add_document_to_index(&mut idx, &extractor, tokenizer, filter, d.id, d);
add_document_to_index(
/*&mut base.index,
&base.arena_index,
&base.arena_doc,*/
&mut index,
&index_arenas.arena_index,
&index_arenas.arena_doc,
&extractor,
tokenizer,
filter,
d.id,
d,
);
}
}
Loading

0 comments on commit 038c28d

Please sign in to comment.