Refactor random number generation and update num_periods in main function
This commit is contained in:
parent
e87d6b7398
commit
d8153408e1
17
src/main.rs
17
src/main.rs
@ -1,6 +1,5 @@
|
||||
use chrono::NaiveDate;
|
||||
use rand::distr::Uniform;
|
||||
use rand::{Rng, rng}; // Import thread_rng for random number generation
|
||||
use rand::Rng; // Import thread_rng for random number generation
|
||||
use rustframe::frame::{Frame, RowIndex};
|
||||
use rustframe::matrix::{BoolMatrix, BoolOps, Matrix, SeriesOps}; // Explicitly list used items
|
||||
use rustframe::utils::{BDateFreq, BDatesList};
|
||||
@ -8,8 +7,8 @@ use std::time::Instant; // Use Instant for timing
|
||||
|
||||
// Helper function to generate a random f64 between 0.0 and 1.0
|
||||
fn generate_random_float() -> f64 {
|
||||
let mut rng = rng(); // Get the thread-local random number generator
|
||||
let uniform = Uniform::new(0.0, 1.0).unwrap(); // Define a uniform distribution range and unwrap the result
|
||||
let mut rng = rand::rng(); // Get the thread-local random number generator
|
||||
let uniform = rand::distr::Uniform::new(0.0, 1.0).unwrap(); // Define a uniform distribution range and unwrap the result
|
||||
rng.sample(&uniform) // Sample a value from the distribution
|
||||
}
|
||||
|
||||
@ -44,7 +43,7 @@ fn main() {
|
||||
|
||||
// --- Configuration ---
|
||||
let start_date_str = "2000-01-01".to_string();
|
||||
let num_periods = 20_000;
|
||||
let num_periods = 1_000;
|
||||
let num_columns = 1_000;
|
||||
let frequency = BDateFreq::Daily;
|
||||
|
||||
@ -129,14 +128,10 @@ fn main() {
|
||||
|
||||
// Complex operation
|
||||
let complex_start_time = Instant::now();
|
||||
let frame_r = &frame_a * &frame_b;
|
||||
let frame_r = &frame_r / &frame_b;
|
||||
let frame_r = &frame_r - &frame_a;
|
||||
let frame_r = &frame_r + &frame_a;
|
||||
let frame_r = &frame_r - &frame_a;
|
||||
let frame_r = &(&(&(&(&frame_a * &frame_b) / &frame_b) - &frame_a) + &frame_a) - &frame_a;
|
||||
|
||||
let frame_r = frame_r.matrix().lt_elementwise(0.0000001);
|
||||
let complex_result = frame_r.any();
|
||||
let complex_result = frame_r.all();
|
||||
let complex_duration = complex_start_time.elapsed();
|
||||
println!("Complex operation duration: {:?}", complex_duration);
|
||||
println!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user