From c306083192f95944c26259f48b9e6918707bc703 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Tue, 27 Aug 2024 13:24:14 +0200 Subject: [PATCH] run cargo fmt --- src/main/rust/Cargo.lock | 7 +++++++ src/main/rust/Cargo.toml | 3 ++- src/main/rust/benches/flare_flo.rs | 6 +++--- src/main/rust/benches/libraries.rs | 4 ++-- src/main/rust/benches/multi_threaded.rs | 6 +++--- src/main/rust/benches/multi_threaded_smol.rs | 4 ++-- src/main/rust/benches/phcs.rs | 6 +++--- src/main/rust/benches/reference_impl.rs | 6 +++--- src/main/rust/benches/single_thread.rs | 6 +++--- src/main/rust/src/bin/libraries.rs | 2 +- .../rust/src/implementations/libraries.rs | 6 +++--- .../src/implementations/multi_threaded.rs | 6 +++--- .../multi_threaded_structured.rs | 19 ++++++++++++------- .../rust/src/implementations/single_thread.rs | 6 +++--- src/main/rust/src/lib.rs | 2 +- src/main/rust/src/main.rs | 1 - src/main/rust/src/models.rs | 2 +- .../utils/write_structured_measurements.rs | 7 +++++-- 18 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/main/rust/Cargo.lock b/src/main/rust/Cargo.lock index 410b248..0ab2a14 100644 --- a/src/main/rust/Cargo.lock +++ b/src/main/rust/Cargo.lock @@ -332,6 +332,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "easy-parallel" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2afbb9b0aef60e4f0d2b18129b6c0dff035a6f7dbbd17c2f38c1432102ee223c" + [[package]] name = "either" version = "1.13.0" @@ -517,6 +523,7 @@ version = "0.1.0" dependencies = [ "bstr", "criterion", + "easy-parallel", "fast-float", "libc", "memchr", diff --git a/src/main/rust/Cargo.toml b/src/main/rust/Cargo.toml index cc81dbf..13a4e55 100644 --- a/src/main/rust/Cargo.toml +++ b/src/main/rust/Cargo.toml @@ -14,6 +14,7 @@ rayon = "1.10.0" rustc-hash = "2.0.0" libc = "0.2.158" smol = "2.0.1" +easy-parallel = "3.3.1" [dev-dependencies] criterion = { version = "0.5.1", features = ["html_reports"] } @@ -54,4 +55,4 @@ panic = "abort" [profile.flamegraph] inherits = "release" debug = true -strip = "none" \ No newline at end of file +strip = "none" diff --git a/src/main/rust/benches/flare_flo.rs b/src/main/rust/benches/flare_flo.rs index 32abb85..07e6a32 100644 --- a/src/main/rust/benches/flare_flo.rs +++ b/src/main/rust/benches/flare_flo.rs @@ -1,9 +1,9 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::flare_flo::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("flareflo", |b| {b.iter(|| run())}); + c.bench_function("flareflo", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/src/main/rust/benches/libraries.rs b/src/main/rust/benches/libraries.rs index ca422f7..8d4ccad 100644 --- a/src/main/rust/benches/libraries.rs +++ b/src/main/rust/benches/libraries.rs @@ -1,8 +1,8 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::libraries::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("libraries", |b| {b.iter(|| run())}); + c.bench_function("libraries", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); diff --git a/src/main/rust/benches/multi_threaded.rs b/src/main/rust/benches/multi_threaded.rs index aadcb82..cde1ed2 100644 --- a/src/main/rust/benches/multi_threaded.rs +++ b/src/main/rust/benches/multi_threaded.rs @@ -1,9 +1,9 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::multi_threaded::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("multithreaded", |b| {b.iter(|| run())}); + c.bench_function("multithreaded", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/src/main/rust/benches/multi_threaded_smol.rs b/src/main/rust/benches/multi_threaded_smol.rs index 68448f1..1165256 100644 --- a/src/main/rust/benches/multi_threaded_smol.rs +++ b/src/main/rust/benches/multi_threaded_smol.rs @@ -1,8 +1,8 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::multi_threaded_smol::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("multithreadedsmol", |b| {b.iter(|| run())}); + c.bench_function("multithreadedsmol", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); diff --git a/src/main/rust/benches/phcs.rs b/src/main/rust/benches/phcs.rs index c6a227a..912abfe 100644 --- a/src/main/rust/benches/phcs.rs +++ b/src/main/rust/benches/phcs.rs @@ -1,9 +1,9 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::phcs::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("phcs", |b| {b.iter(|| run())}); + c.bench_function("phcs", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/src/main/rust/benches/reference_impl.rs b/src/main/rust/benches/reference_impl.rs index 8a6b59c..e7defc1 100644 --- a/src/main/rust/benches/reference_impl.rs +++ b/src/main/rust/benches/reference_impl.rs @@ -1,9 +1,9 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::reference_impl::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("reference", |b| {b.iter(|| run())}); + c.bench_function("reference", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/src/main/rust/benches/single_thread.rs b/src/main/rust/benches/single_thread.rs index 06b8db8..420e2fa 100644 --- a/src/main/rust/benches/single_thread.rs +++ b/src/main/rust/benches/single_thread.rs @@ -1,9 +1,9 @@ -use criterion::{Criterion, criterion_group, criterion_main}; +use criterion::{criterion_group, criterion_main, Criterion}; use onebrc::implementations::single_thread::run; pub fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("singlethread", |b| {b.iter(|| run())}); + c.bench_function("singlethread", |b| b.iter(|| run())); } criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/src/main/rust/src/bin/libraries.rs b/src/main/rust/src/bin/libraries.rs index 55a333b..72d5094 100644 --- a/src/main/rust/src/bin/libraries.rs +++ b/src/main/rust/src/bin/libraries.rs @@ -2,4 +2,4 @@ use onebrc::implementations::libraries::run; fn main() { run(); -} \ No newline at end of file +} diff --git a/src/main/rust/src/implementations/libraries.rs b/src/main/rust/src/implementations/libraries.rs index 37b7d73..bac457f 100644 --- a/src/main/rust/src/implementations/libraries.rs +++ b/src/main/rust/src/implementations/libraries.rs @@ -1,11 +1,11 @@ use crate::models::station_measurements::StationMeasurements; use crate::utils::parse; +use crate::utils::parse::hashstr; use memmap2::MmapOptions; +use std::collections::HashMap; use std::sync::mpsc; use std::time::Instant; use std::{fs::File, thread}; -use std::collections::HashMap; -use crate::utils::parse::hashstr; const DEFAULT_HASHMAP_LENGTH: usize = 10000; @@ -43,7 +43,7 @@ pub fn run() { s.spawn(move || { let mut t_stations: HashMap = HashMap::with_capacity(DEFAULT_HASHMAP_LENGTH); - for line in mmap_slice.split(|&byte| { byte == b'\n' }) { + for line in mmap_slice.split(|&byte| byte == b'\n') { if line.len() == 0 { break; } diff --git a/src/main/rust/src/implementations/multi_threaded.rs b/src/main/rust/src/implementations/multi_threaded.rs index 66cd623..15f95d7 100644 --- a/src/main/rust/src/implementations/multi_threaded.rs +++ b/src/main/rust/src/implementations/multi_threaded.rs @@ -1,11 +1,11 @@ +use crate::models::station_measurements::StationMeasurements; +use crate::utils::parse; +use crate::utils::parse::hashstr; use std::collections::HashMap; use std::io::{BufRead, Seek, SeekFrom}; use std::sync::mpsc; use std::time::Instant; use std::{fs::File, io::BufReader, thread}; -use crate::models::station_measurements::StationMeasurements; -use crate::utils::parse; -use crate::utils::parse::hashstr; const DEFAULT_HASHMAP_LENGTH: usize = 10000; diff --git a/src/main/rust/src/implementations/multi_threaded_structured.rs b/src/main/rust/src/implementations/multi_threaded_structured.rs index 03eca40..f6f43db 100644 --- a/src/main/rust/src/implementations/multi_threaded_structured.rs +++ b/src/main/rust/src/implementations/multi_threaded_structured.rs @@ -1,11 +1,11 @@ +use crate::models::station_measurements::StationMeasurements; +use crate::utils::parse; +use memmap2::MmapOptions; +use rustc_hash::{FxBuildHasher, FxHashMap}; +use std::ffi::CStr; use std::sync::mpsc; use std::time::Instant; use std::{fs::File, thread}; -use std::ffi::CStr; -use memmap2::MmapOptions; -use rustc_hash::{FxBuildHasher, FxHashMap}; -use crate::models::station_measurements::StationMeasurements; -use crate::utils::parse; const DEFAULT_HASHMAP_LENGTH: usize = 10000; @@ -53,11 +53,16 @@ pub fn run() { let (station, temp) = unsafe { line.split_at_unchecked(100) }; let station = { if station[station.len() - 1] == 0u8 { - unsafe { std::str::from_utf8_unchecked(CStr::from_bytes_until_nul(station).unwrap().to_bytes()) } + unsafe { + std::str::from_utf8_unchecked( + CStr::from_bytes_until_nul(station).unwrap().to_bytes(), + ) + } } else { unsafe { std::str::from_utf8_unchecked(station) } } - }.to_owned(); + } + .to_owned(); let temp = parse::temp_new(&temp[1..6]); let measurements_option = t_stations.get_mut(&station); if let Some(measurements) = measurements_option { diff --git a/src/main/rust/src/implementations/single_thread.rs b/src/main/rust/src/implementations/single_thread.rs index fcc90d9..b38f95e 100644 --- a/src/main/rust/src/implementations/single_thread.rs +++ b/src/main/rust/src/implementations/single_thread.rs @@ -1,10 +1,10 @@ +use crate::models::station_measurements::StationMeasurements; +use crate::utils::parse; +use crate::utils::parse::hashstr; use std::collections::HashMap; use std::fs::File; use std::io::{BufRead, BufReader}; use std::time::Instant; -use crate::models::station_measurements::StationMeasurements; -use crate::utils::parse; -use crate::utils::parse::hashstr; const DEFAULT_HASHMAP_LENGTH: usize = 10000; diff --git a/src/main/rust/src/lib.rs b/src/main/rust/src/lib.rs index 3aaa843..eebdea6 100644 --- a/src/main/rust/src/lib.rs +++ b/src/main/rust/src/lib.rs @@ -3,6 +3,6 @@ #![feature(slice_split_once)] #![feature(hash_raw_entry)] +pub mod implementations; pub mod models; pub mod utils; -pub mod implementations; diff --git a/src/main/rust/src/main.rs b/src/main/rust/src/main.rs index ef6ca57..e5aa074 100644 --- a/src/main/rust/src/main.rs +++ b/src/main/rust/src/main.rs @@ -1,4 +1,3 @@ - fn main() { // let now = Instant::now(); // let file = File::open("../../../measurements.txt").expect("File measurements.txt not found"); diff --git a/src/main/rust/src/models.rs b/src/main/rust/src/models.rs index 4253ee4..70e563a 100644 --- a/src/main/rust/src/models.rs +++ b/src/main/rust/src/models.rs @@ -1,2 +1,2 @@ -pub mod station_measurements; pub mod mmap; +pub mod station_measurements; diff --git a/src/main/rust/src/utils/write_structured_measurements.rs b/src/main/rust/src/utils/write_structured_measurements.rs index 3a4995e..d396e5f 100644 --- a/src/main/rust/src/utils/write_structured_measurements.rs +++ b/src/main/rust/src/utils/write_structured_measurements.rs @@ -3,7 +3,8 @@ use std::io::{BufRead, BufReader, BufWriter, Write}; pub fn write_structured_measurements() { let file = File::open("../../../measurements.txt").expect("File measurements.txt not found"); - let structured_file = File::create_new("structured_measurements.txt").expect("Could not create file"); + let structured_file = + File::create_new("structured_measurements.txt").expect("Could not create file"); let mut reader = BufReader::new(&file); let mut writer = BufWriter::new(&structured_file); let mut line = Vec::with_capacity(107); @@ -27,7 +28,9 @@ pub fn write_structured_measurements() { write_line[100] = b';'; write_line[temp_val_start..temp_val_start + temp.len()].clone_from_slice(temp); write_line[106] = b'\n'; - writer.write_all(write_line.as_slice()).expect("Could not write"); + writer + .write_all(write_line.as_slice()) + .expect("Could not write"); line.clear(); } }