mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-21 01:09:26 +00:00
add a database benchmark
This commit is contained in:
@@ -11,8 +11,13 @@ publish = false
|
||||
[features]
|
||||
test = ["dep:rstest"]
|
||||
|
||||
[[bench]]
|
||||
name = "insert_calendar_object"
|
||||
harness = false
|
||||
|
||||
[dev-dependencies]
|
||||
rstest.workspace = true
|
||||
criterion.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tokio.workspace = true
|
||||
|
||||
47
crates/store_sqlite/benches/ical_event.ics
Normal file
47
crates/store_sqlite/benches/ical_event.ics
Normal file
@@ -0,0 +1,47 @@
|
||||
BEGIN:VCALENDAR
|
||||
CALSCALE:GREGORIAN
|
||||
PRODID:-//Ximian//NONSGML Evolution Calendar//EN
|
||||
VERSION:2.0
|
||||
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Berlin
|
||||
X-LIC-LOCATION:Europe/Berlin
|
||||
BEGIN:DAYLIGHT
|
||||
TZNAME:CEST
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
DTSTART:19810329T020000
|
||||
RRULE:FREQ=YEARLY;UNTIL=20370329T010000Z;BYDAY=-1SU;BYMONTH=3
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZNAME:CET
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
DTSTART:19961027T030000
|
||||
RRULE:FREQ=YEARLY;UNTIL=20361026T010000Z;BYDAY=-1SU;BYMONTH=10
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
|
||||
|
||||
BEGIN:VEVENT
|
||||
UID:fa915b604e6e3f36772501ff869439e6a3c5cf67
|
||||
DTSTAMP:20250726T112617Z
|
||||
DTSTART;VALUE=DATE:20250806
|
||||
DTEND;VALUE=DATE:20250807
|
||||
SEQUENCE:2
|
||||
SUMMARY:all day event
|
||||
TRANSP:OPAQUE
|
||||
CLASS:PUBLIC
|
||||
CREATED:20250726T144426Z
|
||||
LAST-MODIFIED:20250726T144426Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER:-PT30M
|
||||
REPEAT:2
|
||||
DURATION:PT15M
|
||||
ACTION:DISPLAY
|
||||
DESCRIPTION:Breakfast meeting with executive\n
|
||||
team at 8:30 AM EST.
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
|
||||
END:VCALENDAR
|
||||
70
crates/store_sqlite/benches/insert_calendar_object.rs
Normal file
70
crates/store_sqlite/benches/insert_calendar_object.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use rustical_ical::{CalendarObject, CalendarObjectType};
|
||||
use rustical_store::{Calendar, CalendarMetadata, CalendarStore};
|
||||
use rustical_store_sqlite::tests::get_test_calendar_store;
|
||||
|
||||
fn benchmark(c: &mut Criterion) {
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let cal_store = runtime.block_on(async {
|
||||
let cal_store = get_test_calendar_store().await;
|
||||
|
||||
cal_store
|
||||
.insert_calendar(Calendar {
|
||||
meta: CalendarMetadata {
|
||||
displayname: Some("Yeet".to_owned()),
|
||||
order: 0,
|
||||
description: None,
|
||||
color: None,
|
||||
},
|
||||
principal: "user".to_owned(),
|
||||
id: "okwow".to_owned(),
|
||||
timezone_id: None,
|
||||
deleted_at: None,
|
||||
synctoken: 0,
|
||||
subscription_url: None,
|
||||
push_topic: "asd".to_owned(),
|
||||
components: vec![
|
||||
CalendarObjectType::Event,
|
||||
CalendarObjectType::Todo,
|
||||
CalendarObjectType::Journal,
|
||||
],
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
cal_store
|
||||
});
|
||||
|
||||
let object = CalendarObject::from_ics(include_str!("ical_event.ics").to_owned(), None).unwrap();
|
||||
|
||||
let batch_size = 1000;
|
||||
let objects: Vec<_> = std::iter::repeat_n(object.clone(), batch_size).collect();
|
||||
|
||||
c.bench_function("put_batch", |b| {
|
||||
b.to_async(&runtime).iter(async || {
|
||||
// yeet
|
||||
cal_store
|
||||
.put_objects("user".to_owned(), "okwow".to_owned(), objects.clone(), true)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
});
|
||||
|
||||
c.bench_function("put_single", |b| {
|
||||
b.to_async(&runtime).iter(async || {
|
||||
// yeet
|
||||
for _ in 0..1000 {
|
||||
cal_store
|
||||
.put_object("user".to_owned(), "okwow".to_owned(), object.clone(), true)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
runtime
|
||||
.block_on(cal_store.delete_calendar("user", "okwow", false))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
criterion_group!(benches, benchmark);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user