Skip to content

Commit

Permalink
Rearrange and extend benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Sep 15, 2024
1 parent fd14f86 commit 3fa0f25
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async-trait = { workspace = true }
axum = { version = "0.7.5", optional = true }
bytemuck = { version = "1.17.1", features = ["derive", "extern_crate_std"], optional = true }
bytes = { version = "1.7.1", optional = true }
criterion = { version = "0.5.1", optional = true }
custom_debug = { workspace = true }
netdev = { version = "0.30.0" }
eyre = { workspace = true }
Expand Down Expand Up @@ -58,7 +59,6 @@ windows-sys = { version = "0.59.0", features = ["Win32_Networking_WinSock"] }

[dev-dependencies]
ascom-alpaca = { path = ".", features = ["client", "server", "test"] }
criterion = { version = "0.5.1" }
ctor = "0.2.8"
serial_test = "3.1.1"
tracing-error = "0.2.0"
Expand All @@ -68,16 +68,16 @@ tracing-subscriber = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread"] }

[[bench]]
name = "image_array"
name = "benches"
harness = false
required-features = ["client", "camera", "test"]
required-features = ["client", "all-devices", "criterion"]

[features]
all-devices = ["camera", "covercalibrator", "dome", "filterwheel", "focuser", "observingconditions", "rotator", "safetymonitor", "switch", "telescope"]

__anydevice = []
test = ["tokio/process"]

__anydevice = []
camera = ["__anydevice", "dep:bytemuck", "dep:mediatype", "dep:ndarray", "dep:serde-ndim", "dep:time"]
covercalibrator = ["__anydevice"]
dome = ["__anydevice"]
Expand Down
4 changes: 4 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use ascom_alpaca::benches;
use criterion::criterion_main;

criterion_main!(benches::client);
41 changes: 0 additions & 41 deletions benches/image_array.rs

This file was deleted.

36 changes: 36 additions & 0 deletions src/client/benches/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::Response;
use crate::api::{ConfiguredDevice, FallibleDeviceType, ImageArray};
use crate::response::ValueResponse;
use crate::ASCOMResult;
use bytes::Bytes;
use criterion::Criterion;
use mime::APPLICATION_JSON;

macro_rules! declare_parsing_benches {
($($name:ident: $ty:ty => $fixture_path:literal,)*) => {
/// Run response parsing benchmarks against stored fixtures.
pub fn benches() {
let _ =
Criterion::default()
.configure_from_args()
$(
.bench_function(stringify!($name), |b| {
b.iter(move || {
<$ty>::from_reqwest(
APPLICATION_JSON,
Bytes::from_static(include_bytes!($fixture_path)),
)
.expect("Failed to parse fixture")
});
})
)*;
}
};
}

declare_parsing_benches! {
parse_configured_devices: ValueResponse<Vec<ConfiguredDevice<FallibleDeviceType>>>
=> "resp_configured_devices.json",
parse_image_array: ASCOMResult<ImageArray>
=> "resp_image_array.json",
}
1 change: 1 addition & 0 deletions src/client/benches/resp_configured_devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Value":[{"DeviceName":"Alpaca Camera Sim","DeviceType":"Camera","DeviceNumber":0,"UniqueID":"9244f002-d9bb-415c-a72c-740de130352f"},{"DeviceName":"Alpaca CoverCalibrator Simulator","DeviceType":"CoverCalibrator","DeviceNumber":0,"UniqueID":"5194e0dd-8b5e-4da4-95af-a33bca177f5d"},{"DeviceName":"Alpaca Dome Simulator","DeviceType":"Dome","DeviceNumber":0,"UniqueID":"0f2b36e0-5d12-4677-b06a-0a8405bd090f"},{"DeviceName":"Alpaca Filter Wheel Simulator","DeviceType":"FilterWheel","DeviceNumber":0,"UniqueID":"b5b6feef-f3c6-4f25-8455-0f21b92cb152"},{"DeviceName":"Alpaca Focuser Simulator","DeviceType":"Focuser","DeviceNumber":0,"UniqueID":"c9bcdd5b-e66b-4708-a007-d186ce1db4a0"},{"DeviceName":"Alpaca Observing Conditions Simulator","DeviceType":"ObservingConditions","DeviceNumber":0,"UniqueID":"85c5bbf3-4ea6-42a4-be37-c889b006b7f4"},{"DeviceName":"Alpaca Rotator Simulator","DeviceType":"Rotator","DeviceNumber":0,"UniqueID":"04749800-5b7d-4428-86a1-95a6b82e99c0"},{"DeviceName":"Alpaca Safety Monitor Simulator","DeviceType":"SafetyMonitor","DeviceNumber":0,"UniqueID":"92c20845-01b0-4cb3-ab39-03ee096e32e3"},{"DeviceName":"Alpaca Switch Simulator","DeviceType":"Switch","DeviceNumber":0,"UniqueID":"50f0238c-f0cd-4f98-b3e9-aaaa18ec5e29"},{"DeviceName":"Alpaca Telescope Simulator","DeviceType":"Telescope","DeviceNumber":0,"UniqueID":"fc1534af-2248-4a65-82ae-8258910f12e9"}],"ClientTransactionID":1,"ServerTransactionID":94395}
1 change: 1 addition & 0 deletions src/client/benches/resp_image_array.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#[cfg(feature = "criterion")]
mod benches;
#[cfg(feature = "criterion")]
pub use benches::benches;

mod discovery;
pub use discovery::{BoundClient as BoundDiscoveryClient, Client as DiscoveryClient};

Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,12 @@ pub use client::Client;
pub use errors::{ASCOMError, ASCOMErrorCode, ASCOMResult};
#[cfg(feature = "server")]
pub use server::{BoundServer, Server};

/// Benchmark groups for Criterion.
///
/// They're defined in the library for access to the private types, but actually used from `benches/benches.rs`.
#[cfg(feature = "criterion")]
pub mod benches {
#[cfg(feature = "client")]
pub use crate::client::benches as client;
}

0 comments on commit 3fa0f25

Please sign in to comment.