use core_api::GraphDb;
use core_storage::types::Value;
use std::time::Instant;
fn main() {
let n: usize = std::env::var("ENTITY_N")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(30_000);
let with_fulltext = std::env::var("NO_FULLTEXT").is_err();
let dir = std::env::temp_dir().join(format!("mdb-entity-open-{n}-{with_fulltext}"));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
println!("building a {n}-entity store, fulltext={with_fulltext}...");
{
let mut db = GraphDb::open(&dir).unwrap();
if with_fulltext {
db.enable_fulltext("Talent", "bio").unwrap();
db.enable_fulltext("Talent", "name").unwrap();
db.enable_fulltext("Company", "name").unwrap();
}
let t = Instant::now();
for i in 0..n {
let label = if i % 10 == 0 { "Company" } else { "Talent" };
db.insert_node(
label,
&format!("{}-{i}", label.to_lowercase()),
vec![
("name".to_string(), Value::Str(format!("name {i}"))),
(
"bio".to_string(),
Value::Str(format!(
"Experienced practitioner number {i} with a background in \
design and delivery across several sectors, focused on \
outcomes and measurement."
)),
),
],
)
.unwrap();
}
println!(" inserted in {:?}", t.elapsed());
db.snapshot().unwrap();
println!(" snapshotted");
}
let mut times = Vec::new();
for _ in 0..5 {
let t = Instant::now();
let db = GraphDb::open(&dir).unwrap();
let elapsed = t.elapsed();
std::hint::black_box(db.stats());
times.push(elapsed);
}
times.sort();
println!(
"\nopen x5 (sorted): {:?}\n median {:?}",
times,
times[times.len() / 2]
);
}