From 424207914bb50b6e30ab2410f2b7cd1cc437efe7 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 28 Feb 2022 21:37:13 -0700 Subject: [PATCH] run over a directory --- nalgebra-sparse/example/spmm.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/nalgebra-sparse/example/spmm.rs b/nalgebra-sparse/example/spmm.rs index 17ae21d0..aa4eb473 100644 --- a/nalgebra-sparse/example/spmm.rs +++ b/nalgebra-sparse/example/spmm.rs @@ -1,5 +1,8 @@ extern crate nalgebra_sparse; use nalgebra_sparse::CsrMatrix; +use std::fs::{self, DirEntry}; +use std::io; +use std::path::Path; use std::time::{Duration, Instant}; #[cfg(feature = "io")] @@ -7,16 +10,20 @@ use nalgebra_sparse::io::load_coo_from_matrix_market_file; fn main() { #[cfg(feature = "io")] { - let sparse_input_matrix = - load_coo_from_matrix_market_file::("./data/crankseg_1.mtx").unwrap(); - let sparse_input_matrix = CsrMatrix::from(&sparse_input_matrix); - let spmm_result = &sparse_input_matrix * &sparse_input_matrix; - let now = Instant::now(); - let spmm_result = &sparse_input_matrix * &sparse_input_matrix; - let spmm_time = now.elapsed().as_millis(); - println!("SGEMM time was {}", spmm_time); - let sum: f64 = spmm_result.triplet_iter().map(|(_, _, v)| v).sum(); - println!("sum of product is {}", sum); + let mut file_iter = fs::read_dir("./data").unwrap(); + for f in file_iter { + println!("Benchmark file {:?}", f); + let f = f.unwrap().path(); + let sparse_input_matrix = load_coo_from_matrix_market_file::(&f).unwrap(); + let sparse_input_matrix = CsrMatrix::from(&sparse_input_matrix); + let spmm_result = &sparse_input_matrix * &sparse_input_matrix; + let now = Instant::now(); + let spmm_result = &sparse_input_matrix * &sparse_input_matrix; + let spmm_time = now.elapsed().as_millis(); + println!("SGEMM time was {}", spmm_time); + let sum: f64 = spmm_result.triplet_iter().map(|(_, _, v)| v).sum(); + println!("sum of product is {}", sum); + } } #[cfg(not(feature = "io"))] {