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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust: [1.70.0, stable]
rust: [1.81.0, stable]
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
Expand All @@ -42,9 +42,9 @@ jobs:
override: true
- name: Clippy
run: cargo clippy -- -D warnings
- name: Check (async-std)
- name: Check (smol)
run: cargo check --features link_to
- name: Run tests (async-std)
- name: Run tests (smol)
run: cargo test --verbose --features link_to
- name: Check (Tokio)
run: cargo check --no-default-features --features tokio-runtime,link_to
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ readme = "README.md"
categories = ["caching", "filesystem"]

[dependencies]
async-std = { version = "1.10.0", features = ["unstable"], optional = true }
digest = "0.10.6"
either = "1.6.1"
futures = { version = "0.3.17", optional = true }
hex = "0.4.3"
memmap2 = { version = "0.5.8", optional = true }
smol = { version = "2.0.0", optional = true }
miette = "5.7.0"
reflink-copy = "0.1.9"
serde = "1.0.130"
Expand All @@ -40,9 +40,10 @@ walkdir = "2.3.2"
libc = { version = "0.2.144", optional = true }

[dev-dependencies]
async-attributes = { version = "1.1.2" }
criterion = "0.4.0"
lazy_static = "1.4.0"
smol-macros = "0.1.1"
macro_rules_attribute = "0.2.0"
tokio = { version = "1.12.0", features = [
"fs",
"io-util",
Expand All @@ -56,8 +57,8 @@ name = "benchmarks"
harness = false

[features]
default = ["async-std", "mmap"]
default = ["smol-runtime", "mmap"]
mmap = ["memmap2", "libc"]
async-std = ["dep:async-std", "futures"]
link_to = []
tokio-runtime = ["tokio", "tokio-stream", "futures"]
smol-runtime = ["smol", "futures"]
54 changes: 27 additions & 27 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#[cfg(feature = "async-std")]
use async_std::fs as afs;
#[cfg(feature = "smol")]
use smol::fs as afs;
#[cfg(feature = "link_to")]
use std::path::PathBuf;
#[cfg(all(test, feature = "tokio"))]
use tokio::fs as afs;

#[cfg(all(test, feature = "async-std"))]
pub use async_std::task::block_on;

#[cfg(all(test, feature = "tokio"))]
lazy_static::lazy_static! {
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
Expand All @@ -22,6 +19,15 @@ where
TOKIO_RUNTIME.block_on(future)
}

#[cfg(all(test, feature = "smol"))]
#[inline]
pub fn block_on<F, T>(future: F) -> T
where
F: std::future::Future<Output = T>,
{
smol::block_on(future)
}

use std::fs::{self, File};
use std::io::prelude::*;

Expand Down Expand Up @@ -62,7 +68,7 @@ fn baseline_read_many_sync(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn baseline_read_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let path = tmp.path().join("test_file");
Expand All @@ -75,7 +81,7 @@ fn baseline_read_async(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn baseline_read_many_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let paths: Vec<_> = (0..)
Expand Down Expand Up @@ -190,7 +196,7 @@ fn read_hash_sync_big_data_xxh3(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn read_hash_many_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
Expand All @@ -212,7 +218,7 @@ fn read_hash_many_async(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn read_hash_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
Expand All @@ -223,7 +229,7 @@ fn read_hash_async(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn read_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
Expand All @@ -234,7 +240,7 @@ fn read_async(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn read_hash_async_big_data(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
Expand Down Expand Up @@ -278,7 +284,7 @@ fn write_hash_xxh3(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn write_hash_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
Expand All @@ -293,7 +299,7 @@ fn write_hash_async(c: &mut Criterion) {
});
}

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn write_hash_async_xxh3(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let cache = tmp.path().to_owned();
Expand Down Expand Up @@ -325,7 +331,7 @@ fn create_tmpfile(tmp: &tempfile::TempDir, buf: &[u8]) -> PathBuf {
}

#[cfg(feature = "link_to")]
#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
fn link_to_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let target = create_tmpfile(&tmp, b"hello world");
Expand All @@ -348,7 +354,7 @@ fn link_to_async(c: &mut Criterion) {
});
}

#[cfg(all(feature = "link_to", any(feature = "async-std", feature = "tokio")))]
#[cfg(all(feature = "link_to", any(feature = "tokio", feature = "smol")))]
fn link_to_hash_async(c: &mut Criterion) {
let tmp = tempfile::tempdir().unwrap();
let target = create_tmpfile(&tmp, b"hello world");
Expand Down Expand Up @@ -405,7 +411,7 @@ criterion_group!(
read_hash_sync_big_data_xxh3,
);

#[cfg(any(feature = "async-std", feature = "tokio"))]
#[cfg(any(feature = "tokio", feature = "smol"))]
criterion_group!(
benches_async,
baseline_read_async,
Expand All @@ -418,23 +424,17 @@ criterion_group!(
read_hash_async_big_data,
);

#[cfg(all(feature = "link_to", any(feature = "async-std", feature = "tokio")))]
#[cfg(all(feature = "link_to", any(feature = "tokio", feature = "smol")))]
criterion_group!(link_to_benches_async, link_to_async, link_to_hash_async,);

#[cfg(feature = "link_to")]
criterion_group!(link_to_benches, link_to_sync, link_to_hash_sync);

#[cfg(all(
feature = "link_to",
not(any(feature = "async-std", feature = "tokio"))
))]
#[cfg(all(feature = "link_to", not(any(feature = "tokio", feature = "smol"))))]
criterion_main!(benches, link_to_benches);
#[cfg(all(
not(feature = "link_to"),
any(feature = "async-std", feature = "tokio")
))]
#[cfg(all(not(feature = "link_to"), any(feature = "tokio", feature = "smol")))]
criterion_main!(benches, benches_async);
#[cfg(all(feature = "link_to", any(feature = "async-std", feature = "tokio")))]
#[cfg(all(feature = "link_to", any(feature = "tokio", feature = "smol")))]
criterion_main!(
benches,
benches_async,
Expand All @@ -443,6 +443,6 @@ criterion_main!(
);
#[cfg(all(
not(feature = "link_to"),
not(any(feature = "async-std", feature = "tokio"))
not(any(feature = "tokio", feature = "smol"))
))]
criterion_main!(benches);
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
@help:
just -l

# Run tests on both runtimes with cargo nextest
# Run tests on all runtimes with cargo nextest
@test:
echo "----------\nasync-std:\n"
echo "----------\nsmol:\n"
cargo nextest run
echo "\n----------\ntokio:\n"
cargo nextest run --no-default-features --features tokio-runtime

# Run benchmarks with `cargo bench`
@bench:
echo "----------\nasync-std:\n"
echo "----------\nsmol:\n"
cargo bench
echo "\n----------\ntokio:\n"
cargo bench --no-default-features --features tokio-runtime

# Run benchmarks with `cargo criterion`
@criterion:
echo "----------\nasync-std:\n"
echo "----------\nsmol:\n"
cargo criterion
echo "\n----------\ntokio:\n"
cargo criterion --no-default-features --features tokio-runtime
Expand Down
Loading
Loading