feat(gpodder_sqlite): added benchmarking support
This commit is contained in:
parent
73988d6264
commit
d329a0e61c
4 changed files with 335 additions and 1 deletions
16
gpodder_sqlite/benches/common.rs
Normal file
16
gpodder_sqlite/benches/common.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use gpodder::{AuthStore, User};
|
||||
use gpodder_sqlite::SqliteRepository;
|
||||
|
||||
pub fn setup() -> (SqliteRepository, Vec<User>) {
|
||||
let store = SqliteRepository::in_memory().unwrap();
|
||||
let mut users = Vec::new();
|
||||
|
||||
for i in 0..1000 {
|
||||
let username = format!("test{}", i + 1);
|
||||
let password_hash = format!("dummyhash{}", i + 1);
|
||||
|
||||
users.push(store.insert_user(&username, &password_hash).unwrap());
|
||||
}
|
||||
|
||||
(store, users)
|
||||
}
|
||||
28
gpodder_sqlite/benches/devices.rs
Normal file
28
gpodder_sqlite/benches/devices.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
mod common;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use gpodder::{DevicePatch, DeviceRepository};
|
||||
|
||||
pub fn bench_devices_for_user(c: &mut Criterion) {
|
||||
let (store, users) = common::setup();
|
||||
|
||||
for i in 0..100000 {
|
||||
store
|
||||
.update_device_info(
|
||||
&users[i % users.len()],
|
||||
&format!("device id {i}"),
|
||||
DevicePatch {
|
||||
caption: Some(format!("device caption {i}")),
|
||||
r#type: None,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
c.bench_function("devices for user", |b| {
|
||||
b.iter(|| store.devices_for_user(&users[0]).unwrap())
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(devices, bench_devices_for_user);
|
||||
criterion_main!(devices);
|
||||
Loading…
Add table
Add a link
Reference in a new issue