-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some bench thanks to criterion.rs
- Loading branch information
1 parent
7fbc73d
commit 4882449
Showing
3 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use fitsrs::Pixels; | ||
|
||
|
||
fn criterion_benchmark_decompression(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("decompression"); | ||
let filenames = &[ | ||
"samples/fits.gsfc.nasa.gov/m13real_rice.fits", | ||
"samples/fits.gsfc.nasa.gov/m13_rice.fits", | ||
"samples/fits.gsfc.nasa.gov/m13_gzip.fits" | ||
]; | ||
|
||
group.bench_function(&format!("original file m13.fits"), |b| b.iter(|| read_image())); | ||
|
||
for filename in filenames { | ||
group.bench_function(&format!("decompress {:?}", filename), |b| b.iter(|| decompress(filename))); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
fn decompress(filename: &str) { | ||
use std::fs::File; | ||
use fitsrs::Fits; | ||
use fitsrs::HDU; | ||
use fitsrs::hdu::data::bintable::DataValue; | ||
|
||
let mut f = File::open(filename).unwrap(); | ||
let reader = std::io::BufReader::new(f); | ||
|
||
let mut hdu_list = Fits::from_reader(reader); | ||
|
||
while let Some(Ok(hdu)) = hdu_list.next() { | ||
match hdu { | ||
HDU::XBinaryTable(hdu) => { | ||
let width = hdu | ||
.get_header() | ||
.get_parsed::<i64>("ZNAXIS1") | ||
.unwrap() | ||
.unwrap() as u32; | ||
let height = hdu | ||
.get_header() | ||
.get_parsed::<i64>("ZNAXIS2") | ||
.unwrap() | ||
.unwrap() as u32; | ||
let pixels = hdu_list | ||
.get_data(&hdu) | ||
.collect::<Vec<_>>(); | ||
|
||
assert!(width * height == pixels.len() as u32); | ||
} | ||
_ => (), | ||
} | ||
} | ||
} | ||
|
||
|
||
fn read_image() { | ||
use std::fs::File; | ||
use fitsrs::Fits; | ||
use fitsrs::HDU; | ||
use fitsrs::hdu::data::bintable::DataValue; | ||
|
||
let mut f = File::open("samples/fits.gsfc.nasa.gov/m13.fits").unwrap(); | ||
let reader = std::io::BufReader::new(f); | ||
|
||
let mut hdu_list = Fits::from_reader(reader); | ||
|
||
while let Some(Ok(hdu)) = hdu_list.next() { | ||
match hdu { | ||
HDU::Primary(hdu) | HDU::XImage(hdu) => { | ||
let width = hdu | ||
.get_header() | ||
.get_parsed::<i64>("NAXIS1") | ||
.unwrap() | ||
.unwrap() as u32; | ||
let height = hdu | ||
.get_header() | ||
.get_parsed::<i64>("NAXIS2") | ||
.unwrap() | ||
.unwrap() as u32; | ||
let pixels = match hdu_list | ||
.get_data(&hdu) | ||
.pixels() { | ||
Pixels::I16(it) => it.collect::<Vec<_>>(), | ||
_ => unreachable!() | ||
}; | ||
|
||
assert!(width * height == pixels.len() as u32); | ||
} | ||
_ => (), | ||
} | ||
} | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark_decompression); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use fitsrs::FITSFile; | ||
|
||
fn open_headers(filename: &str) { | ||
let hdu_list = FITSFile::open(filename).expect("Can find fits file"); | ||
|
||
let mut corrupted = false; | ||
for hdu in hdu_list { | ||
match hdu { | ||
Err(_) => { | ||
corrupted = true; | ||
} | ||
_ => (), | ||
} | ||
} | ||
|
||
assert!(corrupted == false); | ||
} | ||
|
||
fn criterion_benchmark_parse_only_headers(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("parse only headers"); | ||
group.measurement_time(std::time::Duration::from_millis(100)); | ||
|
||
let filenames = &[ | ||
"samples/hipsgen/Npix8.fits", | ||
"samples/hipsgen/Npix9.fits", | ||
"samples/hipsgen/Npix132.fits", | ||
"samples/hipsgen/Npix133.fits", | ||
"samples/hipsgen/Npix134.fits", | ||
"samples/hipsgen/Npix140.fits", | ||
"samples/hipsgen/Npix208.fits", | ||
"samples/hipsgen/Npix282.fits", | ||
"samples/hipsgen/Npix4906.fits", | ||
"samples/hipsgen/Npix691539.fits", | ||
"samples/hips2fits/allsky_panstarrs.fits", | ||
"samples/hips2fits/cutout-CDS_P_HST_PHAT_F475W.fits", | ||
"samples/fits.gsfc.nasa.gov/EUVE.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_FGS.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_FOC.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_FOS.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_HRS.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_NICMOS.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_WFPC_II.fits", | ||
"samples/fits.gsfc.nasa.gov/HST_WFPC_II_bis.fits", | ||
"samples/vizier/NVSSJ235137-362632r.fits", | ||
"samples/vizier/VAR.358.R.fits", | ||
"samples/fits.gsfc.nasa.gov/IUE_LWP.fits", | ||
"samples/misc/bonn.fits", | ||
"samples/misc/EUC_MER_MOSAIC-VIS-FLAG_TILE100158585-1EC1C5_20221211T132329.822037Z_00.00.fits", | ||
"samples/misc/P122_49.fits", | ||
"samples/misc/skv1678175163788.fits", | ||
"samples/misc/SN2923fxjA.fits" | ||
]; | ||
for filename in filenames { | ||
group.bench_function(&format!("open {:?}", filename), |b| b.iter(|| open_headers(filename))); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
|
||
criterion_group!(benches, criterion_benchmark_parse_only_headers); | ||
|
||
|
||
criterion_main!(benches); |