Lines
91.51 %
Functions
100 %
Branches
use criterion::{measurement::WallTime, BenchmarkGroup, BenchmarkId};
use ubyte::ToByteUnit;
pub fn read_blobs(c: &mut BenchmarkGroup<WallTime>, data: &[u8]) {
let client = redis::Client::open("redis://localhost").unwrap();
let mut connection = match client.get_connection() {
Ok(connection) => connection,
Err(err) => {
eprintln!("Error connecting to redis: {:?}", err);
return;
}
};
// The high level api would require allocations. However, by using the low
// level API we can skip the clone.
let data = std::str::from_utf8(data).unwrap();
redis::cmd("SET")
.arg("blob")
.arg(data)
.execute(&mut connection);
c.bench_function(BenchmarkId::new("redis", data.len().bytes()), |b| {
b.iter(|| {
redis::cmd("GET")
.query::<Vec<u8>>(&mut connection)
.unwrap();
});
let runtime = tokio::runtime::Runtime::new().unwrap();
let mut connection = runtime.block_on(async { client.get_async_connection().await.unwrap() });
c.bench_function(BenchmarkId::new("redis-async", data.len().bytes()), |b| {
runtime.block_on(async {
.query_async::<_, Vec<u8>>(&mut connection)
.await
})
pub fn write_blobs(c: &mut BenchmarkGroup<WallTime>, data: &[u8]) {
// Disable saving
redis::cmd("CONFIG")
.arg("SET")
.arg("SAVE")
.arg("")
.query_async::<_, ()>(&mut connection)
pub fn increment(c: &mut BenchmarkGroup<WallTime>) {
c.bench_function("redis", |b| {
redis::cmd("INCR").arg("u64").execute(&mut connection);
c.bench_function("redis-async", |b| {
redis::cmd("INCR")
.arg("u64")