2022-08-06 19:48:10 +03:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
2022-10-01 10:48:11 +03:00
|
|
|
use martin::pg::composite_source::CompositeSource;
|
2022-10-12 11:52:26 +03:00
|
|
|
use martin::pg::dev::make_pool;
|
2022-10-01 10:48:11 +03:00
|
|
|
use martin::pg::function_source::FunctionSource;
|
|
|
|
use martin::pg::table_source::TableSource;
|
2021-07-23 11:04:34 +03:00
|
|
|
use martin::source::{Source, Xyz};
|
2022-10-12 11:52:26 +03:00
|
|
|
use std::collections::HashMap;
|
2021-07-23 11:04:34 +03:00
|
|
|
|
|
|
|
fn mock_table_source(schema: &str, table: &str) -> TableSource {
|
|
|
|
TableSource {
|
2022-05-27 14:03:48 +03:00
|
|
|
id: format!("{schema}.{table}"),
|
2021-07-23 11:04:34 +03:00
|
|
|
schema: schema.to_owned(),
|
|
|
|
table: table.to_owned(),
|
|
|
|
id_column: None,
|
|
|
|
geometry_column: "geom".to_owned(),
|
2021-10-13 14:51:29 +03:00
|
|
|
minzoom: None,
|
|
|
|
maxzoom: None,
|
2021-10-10 12:09:56 +03:00
|
|
|
bounds: None,
|
2021-07-23 11:04:34 +03:00
|
|
|
srid: 3857,
|
|
|
|
extent: Some(4096),
|
|
|
|
buffer: Some(64),
|
|
|
|
clip_geom: Some(true),
|
|
|
|
geometry_type: None,
|
|
|
|
properties: HashMap::new(),
|
2022-10-24 20:45:26 +03:00
|
|
|
unrecognized: HashMap::new(),
|
2021-07-23 11:04:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn mock_function_source(schema: &str, function: &str) -> FunctionSource {
|
|
|
|
FunctionSource {
|
2022-05-27 14:03:48 +03:00
|
|
|
id: format!("{schema}.{function}"),
|
2021-07-23 11:04:34 +03:00
|
|
|
schema: schema.to_owned(),
|
|
|
|
function: function.to_owned(),
|
2021-10-13 14:51:29 +03:00
|
|
|
minzoom: None,
|
|
|
|
maxzoom: None,
|
|
|
|
bounds: None,
|
2022-10-24 20:45:26 +03:00
|
|
|
unrecognized: HashMap::new(),
|
2021-07-23 11:04:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_table_source() {
|
|
|
|
let source = mock_table_source("public", "table_source");
|
|
|
|
let _tilejson = source.get_tilejson();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_table_source_tile() {
|
2022-10-12 11:52:26 +03:00
|
|
|
let pool = make_pool().await;
|
2022-08-15 16:54:48 +03:00
|
|
|
let mut connection = pool.get().await.unwrap();
|
2021-07-23 11:04:34 +03:00
|
|
|
|
|
|
|
let source = mock_table_source("public", "table_source");
|
|
|
|
let xyz = Xyz { z: 0, x: 0, y: 0 };
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let _tile = source.get_tile(&mut connection, &xyz, &None).await.unwrap();
|
2021-07-23 11:04:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_composite_source() {
|
|
|
|
let points1 = mock_table_source("public", "points1");
|
|
|
|
let points2 = mock_table_source("public", "points2");
|
|
|
|
|
|
|
|
let source = CompositeSource {
|
|
|
|
id: "public.points1,public.points2".to_owned(),
|
|
|
|
table_sources: vec![points1, points2],
|
|
|
|
};
|
|
|
|
|
|
|
|
let _tilejson = source.get_tilejson();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_composite_source_tile() {
|
2022-10-12 11:52:26 +03:00
|
|
|
let pool = make_pool().await;
|
2022-08-15 16:54:48 +03:00
|
|
|
let mut connection = pool.get().await.unwrap();
|
2021-07-23 11:04:34 +03:00
|
|
|
|
|
|
|
let points1 = mock_table_source("public", "points1");
|
|
|
|
let points2 = mock_table_source("public", "points2");
|
|
|
|
|
|
|
|
let source = CompositeSource {
|
|
|
|
id: "public.points1,public.points2".to_owned(),
|
|
|
|
table_sources: vec![points1, points2],
|
|
|
|
};
|
|
|
|
|
|
|
|
let xyz = Xyz { z: 0, x: 0, y: 0 };
|
2022-08-15 16:54:48 +03:00
|
|
|
let _tile = source.get_tile(&mut connection, &xyz, &None).await.unwrap();
|
2021-07-23 11:04:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_function_source() {
|
|
|
|
let source = mock_function_source("public", "function_source");
|
|
|
|
let _tilejson = source.get_tilejson();
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn get_function_source_tile() {
|
2022-10-12 11:52:26 +03:00
|
|
|
let pool = make_pool().await;
|
2022-08-15 16:54:48 +03:00
|
|
|
let mut connection = pool.get().await.unwrap();
|
2021-07-23 11:04:34 +03:00
|
|
|
|
|
|
|
let source = mock_function_source("public", "function_source");
|
|
|
|
let xyz = Xyz { z: 0, x: 0, y: 0 };
|
|
|
|
|
2022-08-15 16:54:48 +03:00
|
|
|
let _tile = source.get_tile(&mut connection, &xyz, &None).await.unwrap();
|
2021-07-23 11:04:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn table_source(c: &mut Criterion) {
|
2022-07-06 12:24:45 +03:00
|
|
|
c.bench_function("get_table_source", |b| b.iter(get_table_source));
|
|
|
|
c.bench_function("get_table_source_tile", |b| b.iter(get_table_source_tile));
|
2021-07-23 11:04:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn composite_source(c: &mut Criterion) {
|
2022-07-06 12:24:45 +03:00
|
|
|
c.bench_function("get_composite_source", |b| b.iter(get_composite_source));
|
2021-07-23 11:04:34 +03:00
|
|
|
c.bench_function("get_composite_source_tile", |b| {
|
2022-10-12 11:52:26 +03:00
|
|
|
b.iter(get_composite_source_tile);
|
2021-07-23 11:04:34 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn function_source(c: &mut Criterion) {
|
2022-07-06 12:24:45 +03:00
|
|
|
c.bench_function("get_function_source", |b| b.iter(get_function_source));
|
2021-07-23 11:04:34 +03:00
|
|
|
c.bench_function("get_function_source_tile", |b| {
|
2022-10-12 11:52:26 +03:00
|
|
|
b.iter(get_function_source_tile);
|
2021-07-23 11:04:34 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, table_source, composite_source, function_source);
|
|
|
|
criterion_main!(benches);
|