use std::process::Command;
use std::time::Instant;
use criterion::{Criterion, criterion_group, criterion_main};
use gitway_lib::{GitwayConfig, GitwaySession};
fn integration_enabled() -> bool {
std::env::var("GITWAY_INTEGRATION_TESTS").is_ok_and(|v| v == "1")
}
fn bench_gitway_exec(c: &mut Criterion) {
if !integration_enabled() {
return;
}
let rt = tokio::runtime::Runtime::new().expect("tokio runtime");
c.bench_function("gitway_exec", |b| {
b.iter(|| {
rt.block_on(async {
let config = GitwayConfig::github();
let mut session = GitwaySession::connect(&config)
.await
.expect("gitway connect");
session
.authenticate_best(&config)
.await
.expect("gitway auth");
let _ = session.exec("true").await;
session.close().await.expect("gitway close");
});
});
});
}
fn bench_openssh_exec(c: &mut Criterion) {
if !integration_enabled() {
return;
}
if Command::new("ssh").arg("-V").output().is_err() {
return;
}
c.bench_function("openssh_exec", |b| {
b.iter_custom(|iters| {
let mut total = std::time::Duration::ZERO;
for _ in 0..iters {
let t0 = Instant::now();
let _ = Command::new("ssh")
.args(["-o", "BatchMode=yes", "-T", "git@github.com"])
.output();
total += t0.elapsed();
}
total
});
});
}
criterion_group!(benches, bench_gitway_exec, bench_openssh_exec);
criterion_main!(benches);