diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aea7af7..38496f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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" diff --git a/src/bin/create_measurements.rs b/src/bin/create_measurements.rs index 0958f94..3008a0d 100644 --- a/src/bin/create_measurements.rs +++ b/src/bin/create_measurements.rs @@ -46,6 +46,10 @@ fn generate_measurements( ) -> 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) { diff --git a/src/main.rs b/src/main.rs index 79626df..954b7e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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';', _) => { @@ -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()); } } };