Skip to content

Commit fc9ab79

Browse files
committed
Add benchmark for large array parsing
1 parent 3ebaf55 commit fc9ab79

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ name = "fast_path"
105105
harness = false
106106
required-features = ["bench"]
107107

108+
[[bench]]
109+
name = "large_array_parsing"
110+
harness = false
111+
required-features = ["bench"]
112+
113+
108114
[[example]]
109115
name = "actix_crud"
110116
required-features = ["web-examples"]

benches/large_array_parsing.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use criterion::{Criterion, criterion_group, criterion_main};
2+
use std::hint::black_box;
3+
use tokio::runtime::Runtime;
4+
5+
use fred::prelude::*; // fred
6+
use redis::{AsyncCommands, aio::MultiplexedConnection}; // redis-rs
7+
use rustis::{
8+
client::Client as RustisClient,
9+
commands::{GenericCommands, ListCommands},
10+
}; // rustis
11+
12+
const KEY: &str = "large_list";
13+
14+
async fn setup_data(client: &RustisClient) {
15+
// Cleanup
16+
let _: usize = client.del(KEY).await.unwrap();
17+
18+
// prepare 500 strings of around 100 bytes each to force parser to work on volume
19+
let payloads: Vec<String> = (0..5000)
20+
.map(|i| {
21+
format!(
22+
"user_session_data_buffer_overflow_protection_check_{:05}",
23+
i
24+
)
25+
})
26+
.collect();
27+
28+
client.rpush(KEY, payloads).await.unwrap();
29+
}
30+
31+
async fn bench_rustis(client: RustisClient) {
32+
let _: Vec<String> = black_box(client.lrange(KEY, 0, -1).await.unwrap());
33+
}
34+
35+
async fn bench_fred(client: fred::clients::Client) {
36+
let _: Vec<String> = black_box(client.lrange(KEY, 0, -1).await.unwrap());
37+
}
38+
39+
async fn bench_redis_rs(mut conn: MultiplexedConnection) {
40+
let _: Vec<String> = black_box(conn.lrange(KEY, 0, -1).await.unwrap());
41+
}
42+
43+
fn compare_drivers(c: &mut Criterion) {
44+
let rt = Runtime::new().unwrap();
45+
let redis_host = std::env::var("REDIS_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
46+
47+
// Initialisation des clients (Setup)
48+
let (rustis, fred, redis_rs) = rt.block_on(async {
49+
// rustis
50+
let rustis = RustisClient::connect(redis_host.clone()).await.unwrap();
51+
setup_data(&rustis).await;
52+
// fred
53+
let config = Config::from_url(&format!("redis://{redis_host}:6379/0")).unwrap();
54+
let fred = Builder::from_config(config).build().unwrap();
55+
fred.init().await.unwrap();
56+
// redis-rs
57+
let redis_rs = redis::Client::open(format!("redis://{redis_host}:6379")).unwrap();
58+
let redis_rs = redis_rs.get_multiplexed_async_connection().await.unwrap();
59+
60+
(rustis, fred, redis_rs)
61+
});
62+
63+
let mut group = c.benchmark_group("Large Array Parsing Comparison");
64+
65+
group.bench_function("rustis", |b| {
66+
b.to_async(&rt).iter(|| bench_rustis(rustis.clone()));
67+
});
68+
69+
group.bench_function("fred", |b| {
70+
b.to_async(&rt).iter(|| bench_fred(fred.clone()));
71+
});
72+
73+
group.bench_function("redis-rs", |b| {
74+
b.to_async(&rt).iter(|| bench_redis_rs(redis_rs.clone()));
75+
});
76+
77+
group.finish();
78+
}
79+
80+
criterion_group!(benches, compare_drivers);
81+
criterion_main!(benches);

benches/multiplexer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ async fn setup_data(client: &RustisClient) {
1010
let data: Vec<_> = (0..100)
1111
.map(|i| (format!("key{i}"), format!("value{i}")))
1212
.collect();
13-
// On s'assure que les données sont bien là avant de commencer
1413
let _: () = client.mset(data).await.unwrap();
1514
}
1615

0 commit comments

Comments
 (0)