Skip to content

Commit

Permalink
update MSRV to 1.70 + WASM CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz committed Dec 13, 2024
1 parent d1e11f0 commit e5b973b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 40 deletions.
40 changes: 38 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust_version: ['1.60.0', 'stable', 'nightly']
os: [ubuntu-20.04, ubuntu-22.04, macOS-11, macOS-12, windows-2019, windows-2022]
rust_version: ['1.70.0', 'stable', 'nightly']
os: [ubuntu-22.04, ubuntu-24.04, macOS-13, macOS-14, windows-2019, windows-2022]
steps:
- uses: actions/checkout@v3
- name: Install Rust ${{ matrix.rust_version }}
Expand Down Expand Up @@ -74,6 +74,42 @@ jobs:
run: cross +nightly test --target ${{ matrix.target }} --no-default-features --features=prost -- --test-threads=1
env:
RUSTFLAGS: "-C opt-level=1"
test-wasm-browser:
name: Test ${{ matrix.rust_version }}/${{ matrix.os }} (wasm32-unknown-unknown)
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust_version: ['1.70.0', 'stable', 'nightly']
os: [ubuntu-22.04, ubuntu-24.04, macOS-13, macOS-14, windows-2019, windows-2022]
steps:
- uses: actions/checkout@v3
- name: Install Rust ${{ matrix.rust_version }}
run: rustup default ${{ matrix.rust_version }}
- name: Install wasm32-unknown-unknown target
run: rustup target add wasm32-unknown-unknown
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Run Tests
run: wasm-pack test --node
test-wasi:
name: Test ${{ matrix.rust_version }}/${{ matrix.os }} (wasm32-wasi)
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust_version: ['1.70.0', 'stable', 'nightly']
os: [ubuntu-22.04, ubuntu-24.04, macOS-13, macOS-14, windows-2019, windows-2022]
steps:
- uses: actions/checkout@v3
- name: Install Rust ${{ matrix.rust_version }}
run: rustup default ${{ matrix.rust_version }}
- name: Install wasm32-wasi target
run: rustup target add wasm32-wasi
- name: Install cargo-wasi
run: cargo install cargo-wasi
- name: Install wasmtime
run: curl https://wasmtime.dev/install.sh -sSf | bash
- name: Run Tests
run: cargo wasi test
docs:
runs-on: ubuntu-latest
env:
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
[crate]: https://crates.io/crates/quanta
[docs]: https://docs.rs/quanta

__quanta__ is a high-speed timing library, useful for getting the current time _very quickly_, as
well as manipulating it.
__quanta__ is a high-speed timing library, useful for getting the current time _very quickly_, as well as manipulating
it.

## code of conduct

Expand All @@ -36,10 +36,10 @@ The API documentation of this library can be found at [docs.rs/quanta](https://d

## platform / architecture support

For most major platforms -- Linux, Windows, and macOS -- with processors made around or after 2008,
you should have no problems using `quanta` with full TSC support. `quanta` will always fallback to
the included stdlib timing facilities if TSC support is not present. The biggest caveat to this, as
evidenced in the compatibility matrix below, is that we only support the TSC on x86/x86_64 platforms.
For most major platforms -- Linux, Windows, and macOS -- with processors made around or after 2008, you should have no
problems using `quanta` with full TSC support. `quanta` will always fallback to the included stdlib timing facilities if
TSC support is not present. The biggest caveat to this, as evidenced in the compatibility matrix below, is that we only
support the TSC on `x86`/`x86_64` platforms.


| Platform | stdlib fallback | TSC support? | CI tests? |
Expand All @@ -54,17 +54,17 @@ evidenced in the compatibility matrix below, is that we only support the TSC on

## performance

`quanta` sits neck-and-neck with native OS time facilities: the cost of `Clock::now` is on par
`Instant::now` from the stdlib, if not better.
`quanta` sits neck-and-neck with native OS time facilities: the cost of `Clock::now` is on par `Instant::now` from the
stdlib, if not better.

## why use this over stdlib?

Beyond having a performance edge in specific situations, the ability to use mocked time makes it
easier to actually test that your application is doing the right thing when time is involved.
Beyond having a performance edge in specific situations, the ability to use mocked time makes it easier to actually test
that your application is doing the right thing when time is involved.

Additionally, and as mentioned in the general features section, `quanta` provides a safe/thin
wrapper over accessing the Time Stamp Counter, which allows measuring cycle counts over short
sections of code. This can be relevant/important for accurately measuring performance-critical sections of code.
Additionally, and as mentioned in the general features section, `quanta` provides a safe/thin wrapper over accessing the
Time Stamp Counter, which allows measuring cycle counts over short sections of code. This can be relevant/important for
accurately measuring performance-critical sections of code.

## alternative crates

Expand Down
6 changes: 2 additions & 4 deletions src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ mod tests {
ignore = "WASM thread cannot sleep"
)]
fn test_now() {
let _guard = RECENT_LOCK.lock().unwrap();

let t0 = Instant::now();
thread::sleep(Duration::from_millis(15));
let t1 = Instant::now();
Expand Down Expand Up @@ -328,8 +326,8 @@ mod tests {
let threshold = Duration::from_millis(14);
assert!(
result > threshold,
"t1 should be greater than t0 by at least 14ms, was only {}ms (t0: {}, t1: {})",
result.as_millis(),
"t1 should be greater than t0 by at least 14ms, was only {:?} (t0: {}, t1: {})",
result,
t0.0,
t1.0
);
Expand Down
37 changes: 16 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ impl Clock {
}

#[cfg(test)]
#[allow(dead_code)]
fn reset_timebase(&mut self) -> bool {
match &mut self.inner {
ClockType::Counter(reference, source, calibration) => {
Expand Down Expand Up @@ -541,15 +542,16 @@ fn mul_div_po2_u64(value: u64, numer: u64, denom: u32) -> u64 {

#[cfg(test)]
mod tests {
use super::{Clock, Counter, Monotonic};
use average::{Merge, Variance};
use std::time::{Duration, Instant};
use super::Clock;

#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
mod configure_wasm_tests {
// Until https://github.com/rustwasm/wasm-bindgen/issues/2571 is resolved, these tests will only run in browsers.
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
}
#[cfg(not(target_arch = "wasm32"))]
use super::{Counter, Monotonic};

#[cfg(not(target_arch = "wasm32"))]
use average::{Merge as _, Variance};

#[cfg(not(target_arch = "wasm32"))]
use std::time::{Duration, Instant};

#[test]
#[cfg_attr(
Expand Down Expand Up @@ -595,13 +597,9 @@ mod tests {
assert!(scaled.0 > 0);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
#[cfg_attr(not(feature = "flaky_tests"), ignore)]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
wasm_bindgen_test::wasm_bindgen_test
)]

fn test_reference_source_calibration() {
let mut clock = Clock::new();
let reference = Monotonic::default();
Expand All @@ -619,10 +617,10 @@ mod tests {
// not matching our calculation of wall-clock time to the system's calculation of wall-clock time, in terms
// of their absolute values.
//
// As the system adjusts its clocks over time, whether due to NTP skew, or delays in updating the derived monotonic
// time, and so on, our original measurement base from the reference source -- which we use to anchor how we
// convert our scaled source measurement into the same reference timebase -- can skew further away from the
// current reference time in terms of the rate at which it ticks forward.
// As the system adjusts its clocks over time, whether due to NTP skew, or delays in updating the derived
// monotonic time, and so on, our original measurement base from the reference source -- which we use to
// anchor how we convert our scaled source measurement into the same reference timebase -- can skew further
// away from the current reference time in terms of the rate at which it ticks forward.
//
// Essentially, what we're saying here is that we want to test the scaling ratio that we generated in
// calibration, but not necessarily that the resulting value -- which is meant to be in the same timebase as
Expand Down Expand Up @@ -682,12 +680,9 @@ mod tests {
assert!(overall.mean() < 1000.0);
}

#[cfg(not(target_arch = "wasm32"))]
#[test]
#[cfg_attr(not(feature = "flaky_tests"), ignore)]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown"),
wasm_bindgen_test::wasm_bindgen_test
)]
fn measure_source_reference_self_timing() {
let source = Counter::default();
let reference = Monotonic::default();
Expand Down

0 comments on commit e5b973b

Please sign in to comment.