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

use macos and windows in CI #2

Merged
merged 11 commits into from
May 11, 2024
34 changes: 29 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,43 @@ env:

jobs:
build_and_test:
name: Rust project - latest
runs-on: ubuntu-latest
name: ${{ matrix.os }} ${{ matrix.toolchain }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
os:
- ubuntu-latest
- windows-latest
- macos-latest
- macos-13
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- name: Rustup update
if: matrix.os != 'windows-latest'
run: rustup update ${{ matrix.toolchain }}
- run: rustup default ${{ matrix.toolchain }}
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
key: ${{ runner.os }}-${{ matrix.toolchain }}
- run: cargo build --verbose
- run: cargo test --verbose
- run: ./create_measurements.sh 1_000_000_000
- name: Create measurements
run: cargo r --quiet --bin create_measurements --features=generate --release 1_000_000_000
- run: cargo install hyperfine
- run: ./bench.sh
- name: Build release
run: cargo build --release
- name: Benchmark
if: matrix.os != 'windows-latest'
run: |
python -c "import platform, os; print('OS:', platform.system(), platform.release(), 'Architecture:', platform.machine(), 'CPU threads:', os.cpu_count())"
hyperfine --warmup 0 --runs 5 "./target/release/brc-rs"
- name: Benchmark
if: matrix.os == 'windows-latest'
run: |
python -c "import platform, os; print('OS:', platform.system(), platform.release(), 'Architecture:', platform.machine(), 'CPU threads:', os.cpu_count())"
hyperfine --warmup 0 --runs 5 "target\release\brc-rs.exe"
4 changes: 4 additions & 0 deletions src/bin/create_measurements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ fn generate_measurements<W: Write + Send + 'static>(
) -> std::io::Result<()> {
let start = Instant::now();
let par_count = std::thread::available_parallelism().unwrap();
println!(
"Starting generating {} measurements with {} threads",
size, par_count
);
let task_size = size / par_count;
let mut tasks = vec![task_size; par_count.into()];
for i in 0..(size % par_count) {
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ impl Add<&mut Self> for WeatherStationStats {
}
}
}
fn parse_line(line: &[u8]) -> (&[u8], i64) {
fn parse_line(mut line: &[u8]) -> (&[u8], i64) {
// we know that the measurement is pure ASCII and is at max 5 characters long
// based on this we can find the semicolon faster by doing at most 6 byte comparisons by iterating the reversed bytes
// At the same time, we _are_ iterating through the measurement from the least significant character to the biggest
let mut semicolon_idx = 0;
let mut is_negative = false;
let mut measurement = 0;
// stupid Windows check
if cfg!(windows) && line[line.len() - 1] == b'\r' {
line = &line[..line.len() - 1];
}
for (idx, b) in line.into_iter().rev().take(6).enumerate() {
match (b, idx) {
(b';', _) => {
Expand Down Expand Up @@ -311,7 +315,7 @@ mod tests {
.split(",")
.zip(calc(Some(format!("{}.txt", $file_name))).split(","))
{
assert_eq!(val, expected);
assert_eq!(val.trim(), expected.trim());
}
}
};
Expand Down