From d8153408e1e16b3eccfeebe732f6a7bd59d37cd1 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Fri, 25 Apr 2025 15:39:51 +0100 Subject: [PATCH] Refactor random number generation and update num_periods in main function --- src/main.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 75a25fa..ab47709 100644 --- a/src/main.rs +++ b/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!(