commit 4d358b00b0bb55d20f58d18c3e2cac0a495cdd23
parent 70a3b632b77e94b3659e1065e81b0a81cd99bde6
Author: Antoine A <>
Date: Sat, 13 Jun 2026 11:39:36 +0200
common: improve bench logic
Diffstat:
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/common/taler-common/src/bench.rs b/common/taler-common/src/bench.rs
@@ -22,6 +22,20 @@ use crate::types::utils::InlineStr;
const HEX_TABLE: &[u8; 16] = b"0123456789abcdef";
+/// Fast 16 hex string generation
+pub fn h16() -> InlineStr<32> {
+ let mut raw = [0u8; 16];
+ let mut encoded = [0u8; 32];
+
+ rand::fill(&mut raw);
+ for i in 0..raw.len() {
+ let byte = raw[i];
+ encoded[i * 2] = HEX_TABLE[(byte >> 4) as usize];
+ encoded[i * 2 + 1] = HEX_TABLE[(byte & 0x0F) as usize];
+ }
+ InlineStr::copy_from_slice(&encoded)
+}
+
/// Fast 32 hex string generation
pub fn h32() -> InlineStr<64> {
let mut raw = [0u8; 32];
@@ -86,14 +100,23 @@ fn fmt_measures(times: &[u64]) -> Vec<String> {
pub struct Bench {
db: PgPool,
buf: String,
- amount: usize,
+ pub amount: usize,
iter: usize,
measures: Vec<Vec<String>>,
dirty: bool,
}
impl Bench {
- pub fn new(db: &PgPool, iter: usize, amount: usize) -> Self {
+ pub fn new(db: &PgPool) -> Self {
+ let iter: usize = std::env::var("BENCH_ITER")
+ .ok()
+ .and_then(|v| v.parse().ok())
+ .unwrap_or(10);
+
+ let amount: usize = std::env::var("BENCH_AMOUNT")
+ .ok()
+ .and_then(|v| v.parse().ok())
+ .unwrap_or(100);
println!("Bench {iter} times with {amount} rows");
Self {
db: db.clone(),
@@ -134,7 +157,7 @@ impl Bench {
pub async fn measure<R>(
&mut self,
name: &'static str,
- lambda: impl AsyncFn(usize) -> R,
+ mut lambda: impl AsyncFnMut(usize) -> R,
) -> Vec<R> {
if self.dirty {
// Update database statistics for better perf