|
8 | 8 | //! next: basic_batched_wp.rs |
9 | 9 |
|
10 | 10 | use rusqlite::{Connection, ToSql, Transaction}; |
| 11 | +use rsor::Slice; |
11 | 12 |
|
12 | 13 | mod common; |
13 | 14 |
|
@@ -46,34 +47,35 @@ fn faker(tx: &Transaction, count: i64) { |
46 | 47 |
|
47 | 48 | let mut stmt_with_area = tx.prepare_cached(st1.as_str()).unwrap(); |
48 | 49 | let mut stmt = tx.prepare_cached(st2.as_str()).unwrap(); |
| 50 | + let mut params_with_area = Vec::with_capacity(min_batch_size as usize); |
| 51 | + let mut param_values = Slice::with_capacity(min_batch_size as usize * 3); |
49 | 52 | for _ in 0..(count / min_batch_size) { |
50 | 53 | let with_area = common::get_random_bool(); |
51 | 54 | let age = common::get_random_age(); |
52 | 55 | let is_active = common::get_random_active(); |
53 | | - let mut param_values: Vec<_> = Vec::new(); |
54 | 56 | if with_area { |
55 | | - // lets prepare the batch |
56 | | - let mut vector = Vec::<(String, i8, i8)>::new(); |
57 | 57 | for _ in 0..min_batch_size { |
58 | 58 | let area_code = common::get_random_area_code(); |
59 | | - vector.push((area_code, age, is_active)); |
60 | | - } |
61 | | - for batch in vector.iter() { |
62 | | - param_values.push(&batch.0 as &dyn ToSql); |
63 | | - param_values.push(&batch.1 as &dyn ToSql); |
64 | | - param_values.push(&batch.2 as &dyn ToSql); |
| 59 | + params_with_area.push((area_code,)); |
65 | 60 | } |
| 61 | + let param_values = param_values.fill(|mut v| { |
| 62 | + for params in ¶ms_with_area { |
| 63 | + v.push(¶ms.0 as &dyn ToSql); |
| 64 | + v.push(&age as &dyn ToSql); |
| 65 | + v.push(&is_active as &dyn ToSql); |
| 66 | + } |
| 67 | + v |
| 68 | + }); |
66 | 69 | stmt_with_area.execute(&*param_values).unwrap(); |
| 70 | + params_with_area.clear(); |
67 | 71 | } else { |
68 | | - // lets prepare the batch |
69 | | - let mut vector = Vec::<(i8, i8)>::new(); |
70 | | - for _ in 0..min_batch_size { |
71 | | - vector.push((age, is_active)); |
72 | | - } |
73 | | - for batch in vector.iter() { |
74 | | - param_values.push(&batch.0 as &dyn ToSql); |
75 | | - param_values.push(&batch.1 as &dyn ToSql); |
76 | | - } |
| 72 | + let param_values = param_values.fill(|mut v| { |
| 73 | + for _ in 0..min_batch_size { |
| 74 | + v.push(&age as &dyn ToSql); |
| 75 | + v.push(&is_active as &dyn ToSql); |
| 76 | + } |
| 77 | + v |
| 78 | + }); |
77 | 79 | stmt.execute(&*param_values).unwrap(); |
78 | 80 | } |
79 | 81 | } |
|
0 commit comments