-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created dummy entry generator for benchmark (#273)
- Loading branch information
Showing
13 changed files
with
425 additions
and
329 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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,63 @@ | ||
use num_bigint::BigUint; | ||
use rand::{distributions::Alphanumeric, Rng}; | ||
use rayon::prelude::*; | ||
use std::error::Error; | ||
|
||
use crate::entry::Entry; | ||
|
||
// This is for testing purposes with a large dataset instead of using a CSV file | ||
pub fn generate_dummy_entries<const N_USERS: usize, const N_CURRENCIES: usize>(// entries: &mut [Entry<N_CURRENCIES>], | ||
// cryptocurrencies: &mut [Cryptocurrency], | ||
) -> Result<Vec<Entry<N_CURRENCIES>>, Box<dyn Error>> { | ||
// Ensure N_CURRENCIES is greater than 0. | ||
if N_CURRENCIES == 0 { | ||
return Err("N_CURRENCIES must be greater than 0".into()); | ||
} | ||
|
||
let mut entries: Vec<Entry<N_CURRENCIES>> = vec![Entry::init_empty(); N_USERS]; | ||
|
||
entries.par_iter_mut().for_each(|entry| { | ||
let mut rng = rand::thread_rng(); | ||
|
||
let username: String = (0..10).map(|_| rng.sample(Alphanumeric) as char).collect(); | ||
|
||
let balances: [BigUint; N_CURRENCIES] = | ||
std::array::from_fn(|_| BigUint::from(rng.gen_range(1000..90000) as u32)); | ||
|
||
*entry = Entry::new(username, balances).expect("Failed to create entry"); | ||
}); | ||
|
||
Ok(entries) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::cryptocurrency::Cryptocurrency; | ||
use crate::entry::Entry; | ||
|
||
#[test] | ||
fn test_generate_random_entries() { | ||
const N_USERS: usize = 1 << 17; | ||
const N_CURRENCIES: usize = 2; | ||
|
||
// Attempt to generate random entries | ||
let entries = generate_dummy_entries::<N_USERS, N_CURRENCIES>().unwrap(); | ||
|
||
// Verify that entries are populated | ||
assert_eq!(entries.len(), N_USERS); | ||
for entry in entries { | ||
assert!(!entry.username().is_empty()); | ||
assert_eq!(entry.balances().len(), N_CURRENCIES); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_asset_not_zero() { | ||
const N_USERS: usize = 1 << 17; | ||
const N_CURRENCIES: usize = 0; | ||
|
||
// `N_CURRENCIES` is zero, so this should fail | ||
assert!(generate_dummy_entries::<N_USERS, N_CURRENCIES>().is_err()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
pub mod amortized_kzg; | ||
mod csv_parser; | ||
mod dummy_entries; | ||
mod operation_helpers; | ||
|
||
pub use csv_parser::parse_csv_to_entries; | ||
pub use dummy_entries::generate_dummy_entries; | ||
pub use operation_helpers::*; |