Skip to content

Commit

Permalink
MISC: use 1.76 (stable) instead of nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
tcztzy committed Feb 23, 2024
1 parent 9bfcaff commit d4ed549
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ pyo3-polars = { version = "0.11.1", optional = true }
serde = { version = "1.0.195", features = ["derive"] }
tempfile = "3.9.0"

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }

[[bench]]
name = "my_benchmark"
harness = false

[features]
default = []
extension-module = [
Expand Down
37 changes: 37 additions & 0 deletions benches/my_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::os::unix::ffi::OsStrExt;

use argweavers::{ffi, sites::Sites};
use autocxx::prelude::*;
use criterion::{criterion_group, criterion_main, Criterion};

fn ffi_read_sites() {
let mut s = ffi::Sites::new("", c_int(0), c_int(0)).within_unique_ptr();
let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let _ok = unsafe {
ffi::read_sites1(
path.join("examples/sim1/sim1.sites")
.as_mut_os_string()
.as_bytes()
.as_ptr() as *const i8,
std::pin::Pin::<&mut ffi::Sites>::into_inner_unchecked(s.pin_mut()),
c_int(-1),
c_int(-1),
false,
)
};
}

fn read_sites() {
let path = std::path::PathBuf::from("examples/sim1/sim1.sites");
let _sites = Sites::from_path(path).unwrap();
}

fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("read_sites");
group.bench_function("ffi_read_sites", |b| b.iter(ffi_read_sites));
group.bench_function("read_sites", |b| b.iter(read_sites));
group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly"
channel = "1.76"
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(test)]
#[cfg(feature = "extension-module")]
use pyo3::prelude::*;

Expand Down
11 changes: 0 additions & 11 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate test;

use std::fs::read_to_string;
use std::os::unix::ffi::OsStrExt;

Expand All @@ -26,10 +24,6 @@ fn test_ffi_read_sites() {
assert!(ok);
}

#[bench]
fn bench_ffi_read_sites(b: &mut test::Bencher) {
b.iter(test_ffi_read_sites);
}
#[test]
fn test_from_path() {
let path = std::path::PathBuf::from("examples/sim1/sim1.sites");
Expand Down Expand Up @@ -61,8 +55,3 @@ fn test_try_into_ffi_sites() {
let num_sites: i32 = ffi_sites.get_num_sites().into();
assert_eq!(num_sites, 170);
}

#[bench]
fn bench_from_path(b: &mut test::Bencher) {
b.iter(test_from_path);
}

0 comments on commit d4ed549

Please sign in to comment.