aboutsummaryrefslogtreecommitdiffstats
path: root/benches/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'benches/utils.rs')
-rw-r--r--benches/utils.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/benches/utils.rs b/benches/utils.rs
new file mode 100644
index 0000000..9f20e3c
--- /dev/null
+++ b/benches/utils.rs
@@ -0,0 +1,46 @@
+use log_db::*;
+use rand::distributions::Alphanumeric;
+use rand::Rng;
+use std::fmt::Debug;
+use std::io;
+
+// Function to generate a random integer
+pub fn random_int() -> i64 {
+ let mut rng = rand::thread_rng();
+ rng.gen_range(0..1000) // Random number between 0 and 1000
+}
+
+// Function to generate a random string
+pub fn random_string(len: usize) -> String {
+ let mut rng = rand::thread_rng();
+ (0..len).map(|_| rng.sample(Alphanumeric) as char).collect()
+}
+
+// Function to generate random bytes
+pub fn random_bytes(len: usize) -> Vec<u8> {
+ let mut rng = rand::thread_rng();
+ (0..len).map(|_| rng.gen()).collect()
+}
+
+// Function to generate a random record
+pub fn random_record() -> Record {
+ Record {
+ values: vec![
+ RecordValue::Int(random_int()), // Random int value
+ RecordValue::String(random_string(5)), // Random string of length 5
+ RecordValue::Bytes(random_bytes(10)), // Random bytes of length 10
+ ],
+ }
+}
+
+pub fn prefill_db_with_n_records<T: Eq + Clone + Debug>(
+ db: &mut DB<T>,
+ n: usize,
+) -> Result<(), io::Error> {
+ for _ in 0..n {
+ let record = random_record();
+ db.upsert(&record)?;
+ }
+
+ Ok(())
+}