Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow set and add methods to take uint types in addition to &str #28

Merged
merged 10 commits into from
Sep 5, 2024
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.
Keep a running log of your changes with each PR under the `[Unreleased] - ReleaseDate` header.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Expand All @@ -9,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Changed

- `set` and `add` methods can now accept `uint`-type argument for value in addition to `&str` and `&String` types. The original implementation used an `AsRef` trait bound, which has been replaced with a custom `AsMemcachedValue` trait bound that should cover all of the applicable incoming types.

## [0.3.0] - 2024-08-30

### Added
Expand Down
92 changes: 82 additions & 10 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ fn bench_get(c: &mut Criterion) {
});
}

fn bench_set(c: &mut Criterion) {
fn bench_set_with_string(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("set_small", |b| {
c.bench_function("set_small_with_string", |b| {
b.to_async(&rt).iter_custom(|iters| async move {
let mut client = setup_client().await;
let start = std::time::Instant::now();
Expand All @@ -45,6 +45,51 @@ fn bench_set(c: &mut Criterion) {
});
}

fn bench_set_with_u64(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("set_small_with_int", |b| {
b.to_async(&rt).iter_custom(|iters| async move {
let mut client = setup_client().await;
let start = std::time::Instant::now();
for _ in 0..iters {
let _ = client.set("foo", 1 as u64, None, None).await;
}
start.elapsed()
});
});
}

fn bench_add_with_string(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("add_small_with_string", |b| {
b.to_async(&rt).iter_custom(|iters| async move {
let mut client = setup_client().await;
let start = std::time::Instant::now();
for _ in 0..iters {
let _ = client.add("foo", "bar", None, None).await;
}
start.elapsed()
});
});
}

fn bench_add_with_u64(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("add_small_with_int", |b| {
b.to_async(&rt).iter_custom(|iters| async move {
let mut client = setup_client().await;
let start = std::time::Instant::now();
for _ in 0..iters {
let _ = client.add("foo", 1 as u64, None, None).await;
}
start.elapsed()
});
});
}

fn bench_get_many(c: &mut Criterion) {
let rt = Runtime::new().unwrap();
let keys = &["foo", "bar", "baz"];
Expand All @@ -68,16 +113,36 @@ fn bench_get_many(c: &mut Criterion) {
});
}

fn bench_set_large(c: &mut Criterion) {
fn bench_set_large_with_string(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("set_large_with_string", |b| {
b.to_async(&rt).iter_custom(|iters| async move {
let mut client = setup_client().await;
let large_payload = "a".repeat(LARGE_PAYLOAD_SIZE);
let start = std::time::Instant::now();
for _ in 0..iters {
let _ = client
.set("large_foo", large_payload.as_str(), None, None)
.await;
}
start.elapsed()
});
});
}

fn bench_add_large_with_string(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("set_large", |b| {
c.bench_function("add_large_with_string", |b| {
b.to_async(&rt).iter_custom(|iters| async move {
let mut client = setup_client().await;
let large_payload = "a".repeat(LARGE_PAYLOAD_SIZE);
let start = std::time::Instant::now();
for _ in 0..iters {
let _ = client.set("large_foo", &large_payload, None, None).await;
let _ = client
.add("large_foo", large_payload.as_str(), None, None)
.await;
}
start.elapsed()
});
Expand All @@ -91,7 +156,7 @@ fn bench_get_large(c: &mut Criterion) {
rt.block_on(async {
let mut client = setup_client().await;
client
.set("large_foo", &large_payload, None, None)
.set("large_foo", large_payload.as_str(), None, None)
.await
.unwrap();
});
Expand All @@ -116,7 +181,10 @@ fn bench_get_many_large(c: &mut Criterion) {
rt.block_on(async {
let mut client = setup_client().await;
for key in keys {
client.set(key, &large_payload, None, None).await.unwrap();
client
.set(key, large_payload.as_str(), None, None)
.await
.unwrap();
}
});

Expand All @@ -137,7 +205,7 @@ fn bench_increment(c: &mut Criterion) {

rt.block_on(async {
let mut client = setup_client().await;
client.set("foo", "0", None, None).await.unwrap();
client.set("foo", 0 as u64, None, None).await.unwrap();
});

c.bench_function("increment", |b| {
Expand Down Expand Up @@ -218,9 +286,13 @@ fn bench_decrement_no_reply(c: &mut Criterion) {
criterion_group!(
benches,
bench_get,
bench_set,
bench_set_with_string,
bench_set_with_u64,
bench_add_with_string,
bench_add_with_u64,
bench_get_many,
bench_set_large,
bench_set_large_with_string,
bench_add_large_with_string,
bench_get_large,
bench_get_many_large,
bench_increment,
Expand Down
Loading
Loading