(workload: Vec<Operation>)
| 59 | } |
| 60 | |
| 61 | fn profile_workload(workload: Vec<Operation>) { |
| 62 | let mut tree = BPlusTreeMap::new(16).unwrap(); |
| 63 | let mut profiles: HashMap<String, ProfileData> = HashMap::new(); |
| 64 | |
| 65 | // Pre-populate tree |
| 66 | for i in 0..50_000 { |
| 67 | tree.insert(i, format!("value_{}", i)); |
| 68 | } |
| 69 | |
| 70 | println!("Executing {} operations...", workload.len()); |
| 71 | let total_start = Instant::now(); |
| 72 | |
| 73 | for op in workload { |
| 74 | match op { |
| 75 | Operation::Delete(key) => { |
| 76 | let start = Instant::now(); |
| 77 | let result = tree.remove(&key); |
| 78 | let duration = start.elapsed(); |
| 79 | |
| 80 | profiles |
| 81 | .entry("remove".to_string()) |
| 82 | .or_insert_with(ProfileData::new) |
| 83 | .record(duration); |
| 84 | |
| 85 | // Track successful vs failed deletes |
| 86 | if result.is_some() { |
| 87 | profiles |
| 88 | .entry("successful_delete".to_string()) |
| 89 | .or_insert_with(ProfileData::new) |
| 90 | .record(duration); |
| 91 | } else { |
| 92 | profiles |
| 93 | .entry("failed_delete".to_string()) |
| 94 | .or_insert_with(ProfileData::new) |
| 95 | .record(duration); |
| 96 | } |
| 97 | } |
| 98 | Operation::Insert(key, value) => { |
| 99 | let start = Instant::now(); |
| 100 | tree.insert(key, value); |
| 101 | let duration = start.elapsed(); |
| 102 | |
| 103 | profiles |
| 104 | .entry("insert".to_string()) |
| 105 | .or_insert_with(ProfileData::new) |
| 106 | .record(duration); |
| 107 | } |
| 108 | Operation::Lookup(key) => { |
| 109 | let start = Instant::now(); |
| 110 | tree.get(&key); |
| 111 | let duration = start.elapsed(); |
| 112 | |
| 113 | profiles |
| 114 | .entry("lookup".to_string()) |
| 115 | .or_insert_with(ProfileData::new) |
| 116 | .record(duration); |
| 117 | } |
| 118 | } |
no test coverage detected