Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ sqlx = { version = "0.5.2", features = ["runtime-tokio-native-tls", "sqlite"]}
tokio = {version = "1.5.0", features = ["full"]}
rand = "0.8.3"
num_cpus = "1.0"
rusqlite = "0.25.3"
rusqlite = "0.25.3"
rsor = "0.1"
38 changes: 20 additions & 18 deletions src/bin/basic_batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! next: basic_batched_wp.rs

use rusqlite::{Connection, ToSql, Transaction};
use rsor::Slice;

mod common;

Expand Down Expand Up @@ -46,34 +47,35 @@ fn faker(tx: &Transaction, count: i64) {

let mut stmt_with_area = tx.prepare_cached(st1.as_str()).unwrap();
let mut stmt = tx.prepare_cached(st2.as_str()).unwrap();
let mut params_with_area = Vec::with_capacity(min_batch_size as usize);
let mut param_values = Slice::with_capacity(min_batch_size as usize * 3);
for _ in 0..(count / min_batch_size) {
let with_area = common::get_random_bool();
let age = common::get_random_age();
let is_active = common::get_random_active();
let mut param_values: Vec<_> = Vec::new();
if with_area {
// lets prepare the batch
let mut vector = Vec::<(String, i8, i8)>::new();
for _ in 0..min_batch_size {
let area_code = common::get_random_area_code();
vector.push((area_code, age, is_active));
}
for batch in vector.iter() {
param_values.push(&batch.0 as &dyn ToSql);
param_values.push(&batch.1 as &dyn ToSql);
param_values.push(&batch.2 as &dyn ToSql);
params_with_area.push((area_code,));
}
let param_values = param_values.fill(|mut v| {
for params in &params_with_area {
v.push(&params.0 as &dyn ToSql);
v.push(&age as &dyn ToSql);
v.push(&is_active as &dyn ToSql);
}
v
});
stmt_with_area.execute(&*param_values).unwrap();
params_with_area.clear();
} else {
// lets prepare the batch
let mut vector = Vec::<(i8, i8)>::new();
for _ in 0..min_batch_size {
vector.push((age, is_active));
}
for batch in vector.iter() {
param_values.push(&batch.0 as &dyn ToSql);
param_values.push(&batch.1 as &dyn ToSql);
}
let param_values = param_values.fill(|mut v| {
for _ in 0..min_batch_size {
v.push(&age as &dyn ToSql);
v.push(&is_active as &dyn ToSql);
}
v
});
stmt.execute(&*param_values).unwrap();
}
}
Expand Down