Skip to content

Commit e5b973b

Browse files
committed
update MSRV to 1.70 + WASM CI tests
1 parent d1e11f0 commit e5b973b

File tree

4 files changed

+69
-40
lines changed

4 files changed

+69
-40
lines changed

Diff for: .github/workflows/ci.yml

+38-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
runs-on: ${{ matrix.os }}
3131
strategy:
3232
matrix:
33-
rust_version: ['1.60.0', 'stable', 'nightly']
34-
os: [ubuntu-20.04, ubuntu-22.04, macOS-11, macOS-12, windows-2019, windows-2022]
33+
rust_version: ['1.70.0', 'stable', 'nightly']
34+
os: [ubuntu-22.04, ubuntu-24.04, macOS-13, macOS-14, windows-2019, windows-2022]
3535
steps:
3636
- uses: actions/checkout@v3
3737
- name: Install Rust ${{ matrix.rust_version }}
@@ -74,6 +74,42 @@ jobs:
7474
run: cross +nightly test --target ${{ matrix.target }} --no-default-features --features=prost -- --test-threads=1
7575
env:
7676
RUSTFLAGS: "-C opt-level=1"
77+
test-wasm-browser:
78+
name: Test ${{ matrix.rust_version }}/${{ matrix.os }} (wasm32-unknown-unknown)
79+
runs-on: ${{ matrix.os }}
80+
strategy:
81+
matrix:
82+
rust_version: ['1.70.0', 'stable', 'nightly']
83+
os: [ubuntu-22.04, ubuntu-24.04, macOS-13, macOS-14, windows-2019, windows-2022]
84+
steps:
85+
- uses: actions/checkout@v3
86+
- name: Install Rust ${{ matrix.rust_version }}
87+
run: rustup default ${{ matrix.rust_version }}
88+
- name: Install wasm32-unknown-unknown target
89+
run: rustup target add wasm32-unknown-unknown
90+
- name: Install wasm-pack
91+
run: cargo install wasm-pack
92+
- name: Run Tests
93+
run: wasm-pack test --node
94+
test-wasi:
95+
name: Test ${{ matrix.rust_version }}/${{ matrix.os }} (wasm32-wasi)
96+
runs-on: ${{ matrix.os }}
97+
strategy:
98+
matrix:
99+
rust_version: ['1.70.0', 'stable', 'nightly']
100+
os: [ubuntu-22.04, ubuntu-24.04, macOS-13, macOS-14, windows-2019, windows-2022]
101+
steps:
102+
- uses: actions/checkout@v3
103+
- name: Install Rust ${{ matrix.rust_version }}
104+
run: rustup default ${{ matrix.rust_version }}
105+
- name: Install wasm32-wasi target
106+
run: rustup target add wasm32-wasi
107+
- name: Install cargo-wasi
108+
run: cargo install cargo-wasi
109+
- name: Install wasmtime
110+
run: curl https://wasmtime.dev/install.sh -sSf | bash
111+
- name: Run Tests
112+
run: cargo wasi test
77113
docs:
78114
runs-on: ubuntu-latest
79115
env:

Diff for: README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
[crate]: https://crates.io/crates/quanta
1616
[docs]: https://docs.rs/quanta
1717

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

2121
## code of conduct
2222

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

3737
## platform / architecture support
3838

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

4444

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

5555
## performance
5656

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

6060
## why use this over stdlib?
6161

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

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

6969
## alternative crates
7070

Diff for: src/instant.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ mod tests {
292292
ignore = "WASM thread cannot sleep"
293293
)]
294294
fn test_now() {
295-
let _guard = RECENT_LOCK.lock().unwrap();
296-
297295
let t0 = Instant::now();
298296
thread::sleep(Duration::from_millis(15));
299297
let t1 = Instant::now();
@@ -328,8 +326,8 @@ mod tests {
328326
let threshold = Duration::from_millis(14);
329327
assert!(
330328
result > threshold,
331-
"t1 should be greater than t0 by at least 14ms, was only {}ms (t0: {}, t1: {})",
332-
result.as_millis(),
329+
"t1 should be greater than t0 by at least 14ms, was only {:?} (t0: {}, t1: {})",
330+
result,
333331
t0.0,
334332
t1.0
335333
);

Diff for: src/lib.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ impl Clock {
452452
}
453453

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

542543
#[cfg(test)]
543544
mod tests {
544-
use super::{Clock, Counter, Monotonic};
545-
use average::{Merge, Variance};
546-
use std::time::{Duration, Instant};
545+
use super::Clock;
547546

548-
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
549-
mod configure_wasm_tests {
550-
// Until https://github.com/rustwasm/wasm-bindgen/issues/2571 is resolved, these tests will only run in browsers.
551-
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
552-
}
547+
#[cfg(not(target_arch = "wasm32"))]
548+
use super::{Counter, Monotonic};
549+
550+
#[cfg(not(target_arch = "wasm32"))]
551+
use average::{Merge as _, Variance};
552+
553+
#[cfg(not(target_arch = "wasm32"))]
554+
use std::time::{Duration, Instant};
553555

554556
#[test]
555557
#[cfg_attr(
@@ -595,13 +597,9 @@ mod tests {
595597
assert!(scaled.0 > 0);
596598
}
597599

600+
#[cfg(not(target_arch = "wasm32"))]
598601
#[test]
599602
#[cfg_attr(not(feature = "flaky_tests"), ignore)]
600-
#[cfg_attr(
601-
all(target_arch = "wasm32", target_os = "unknown"),
602-
wasm_bindgen_test::wasm_bindgen_test
603-
)]
604-
605603
fn test_reference_source_calibration() {
606604
let mut clock = Clock::new();
607605
let reference = Monotonic::default();
@@ -619,10 +617,10 @@ mod tests {
619617
// not matching our calculation of wall-clock time to the system's calculation of wall-clock time, in terms
620618
// of their absolute values.
621619
//
622-
// As the system adjusts its clocks over time, whether due to NTP skew, or delays in updating the derived monotonic
623-
// time, and so on, our original measurement base from the reference source -- which we use to anchor how we
624-
// convert our scaled source measurement into the same reference timebase -- can skew further away from the
625-
// current reference time in terms of the rate at which it ticks forward.
620+
// As the system adjusts its clocks over time, whether due to NTP skew, or delays in updating the derived
621+
// monotonic time, and so on, our original measurement base from the reference source -- which we use to
622+
// anchor how we convert our scaled source measurement into the same reference timebase -- can skew further
623+
// away from the current reference time in terms of the rate at which it ticks forward.
626624
//
627625
// Essentially, what we're saying here is that we want to test the scaling ratio that we generated in
628626
// calibration, but not necessarily that the resulting value -- which is meant to be in the same timebase as
@@ -682,12 +680,9 @@ mod tests {
682680
assert!(overall.mean() < 1000.0);
683681
}
684682

683+
#[cfg(not(target_arch = "wasm32"))]
685684
#[test]
686685
#[cfg_attr(not(feature = "flaky_tests"), ignore)]
687-
#[cfg_attr(
688-
all(target_arch = "wasm32", target_os = "unknown"),
689-
wasm_bindgen_test::wasm_bindgen_test
690-
)]
691686
fn measure_source_reference_self_timing() {
692687
let source = Counter::default();
693688
let reference = Monotonic::default();

0 commit comments

Comments
 (0)