mirror of
https://github.com/NexVeridian/wikidata-to-surrealdb.git
synced 2025-09-02 09:59:13 +00:00
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use anyhow::{Error, Ok, Result};
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
use pprof::criterion::{Output, PProfProfiler};
|
|
use std::{env, time::Duration};
|
|
use surrealdb::{engine::local::Db, Surreal};
|
|
use tokio::runtime::Runtime;
|
|
|
|
use init_reader::File_Format;
|
|
use wikidata_to_surrealdb::utils::*;
|
|
|
|
async fn inti_db() -> Result<Surreal<Db>, Error> {
|
|
env::set_var("WIKIDATA_LANG", "en");
|
|
env::set_var("OVERWRITE_DB", "true");
|
|
|
|
let db = init_db::create_db_mem().await?;
|
|
|
|
Ok(db)
|
|
}
|
|
|
|
fn bench(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("Create DB Entities");
|
|
|
|
group.bench_function("Bulk Insert", |b| {
|
|
b.iter(|| {
|
|
let rt = Runtime::new().unwrap();
|
|
rt.block_on(async {
|
|
let db = inti_db().await.unwrap();
|
|
let reader = File_Format::new("json")
|
|
.await
|
|
.reader("tests/data/bench.json")
|
|
.await
|
|
.unwrap();
|
|
|
|
CreateVersion::Bulk
|
|
.run(Some(db.clone()), reader, None, 1000, 100)
|
|
.await
|
|
.unwrap();
|
|
})
|
|
})
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group! {
|
|
name = benches;
|
|
config = Criterion::default().with_profiler(PProfProfiler::new(120, Output::Protobuf)).measurement_time(Duration::from_secs(50));
|
|
targets= bench
|
|
}
|
|
criterion_main!(benches);
|