-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dd4127
commit 4d6515b
Showing
11 changed files
with
545 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#![cfg(nightly)] | ||
#![feature(test)] | ||
#![allow(clippy::suspicious_map)] | ||
|
||
extern crate test; | ||
|
||
use once_cell::sync::Lazy; | ||
use serde::Deserialize; | ||
use std::{fs, future::Future, path::PathBuf}; | ||
use test::Bencher; | ||
use tokio::runtime::Runtime; | ||
|
||
use amadeus::prelude::*; | ||
|
||
static RT: Lazy<Runtime> = Lazy::new(|| { | ||
tokio::runtime::Builder::new() | ||
.threaded_scheduler() | ||
.enable_all() | ||
.build() | ||
.unwrap() | ||
}); | ||
static POOL: Lazy<ThreadPool> = Lazy::new(|| ThreadPool::new(None).unwrap()); | ||
|
||
#[derive(Data, Clone, Deserialize, PartialEq, PartialOrd, Debug)] | ||
struct GameDerived { | ||
a: String, | ||
b: String, | ||
c: String, | ||
d: String, | ||
e: u32, | ||
f: String, | ||
} | ||
|
||
#[derive(Data, Clone, PartialEq, PartialOrd, Debug)] | ||
struct GameDerived2 { | ||
a: String, | ||
b: String, | ||
c: String, | ||
d: String, | ||
e: u64, | ||
f: String, | ||
} | ||
|
||
#[bench] | ||
fn csv_typed(b: &mut Bencher) { | ||
let file = "amadeus-testing/csv/game.csv"; // 2,600,000 bytes | ||
run(b, file, || async { | ||
let rows = Csv::<_, GameDerived>::new(vec![PathBuf::from(file)]) | ||
.await | ||
.unwrap(); | ||
assert_eq!( | ||
rows.par_stream() | ||
.map(|row: Result<_, _>| row.unwrap()) | ||
.count(&*POOL) | ||
.await, | ||
100_000 | ||
); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn csv_typed_serde(b: &mut Bencher) { | ||
let file = "amadeus-testing/csv/game.csv"; // 2,600,000 bytes | ||
run(b, file, || async { | ||
let mut rows = serde_csv::ReaderBuilder::new() | ||
.has_headers(false) | ||
.from_path(file) | ||
.unwrap(); | ||
assert_eq!(rows.deserialize::<GameDerived>().count(), 100_000); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn csv_untyped(b: &mut Bencher) { | ||
let file = "amadeus-testing/csv/game.csv"; // 2,600,000 bytes | ||
run(b, file, || async { | ||
let rows = Csv::<_, Value>::new(vec![PathBuf::from(file)]) | ||
.await | ||
.unwrap(); | ||
assert_eq!( | ||
rows.par_stream() | ||
.map(|row: Result<_, _>| row.unwrap()) | ||
.count(&*POOL) | ||
.await, | ||
100_000 | ||
); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn csv_untyped_serde(b: &mut Bencher) { | ||
let file = "amadeus-testing/csv/game.csv"; // 2,600,000 bytes | ||
run(b, file, || async { | ||
let mut rows = serde_csv::ReaderBuilder::new() | ||
.has_headers(false) | ||
.from_path(file) | ||
.unwrap(); | ||
assert_eq!(rows.records().count(), 100_000); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn csv_untyped_downcase(b: &mut Bencher) { | ||
let file = "amadeus-testing/csv/game.csv"; // 2,600,000 bytes | ||
run(b, file, || async { | ||
let rows = Csv::<_, Value>::new(vec![PathBuf::from(file)]) | ||
.await | ||
.unwrap(); | ||
assert_eq!( | ||
rows.par_stream() | ||
.map(|row: Result<_, _>| { | ||
let _: GameDerived2 = row.unwrap().downcast().unwrap(); | ||
}) | ||
.count(&*POOL) | ||
.await, | ||
100_000 | ||
); | ||
}) | ||
} | ||
|
||
fn run<F>(b: &mut Bencher, file: &str, mut task: impl FnMut() -> F) | ||
where | ||
F: Future<Output = ()>, | ||
{ | ||
RT.enter(|| { | ||
let _ = Lazy::force(&POOL); | ||
b.bytes = fs::metadata(file).unwrap().len(); | ||
b.iter(|| RT.handle().block_on(task())) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#![cfg(nightly)] | ||
#![feature(test)] | ||
#![allow(clippy::suspicious_map)] | ||
|
||
extern crate test; | ||
|
||
use once_cell::sync::Lazy; | ||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; | ||
use std::{future::Future, mem}; | ||
use test::Bencher; | ||
use tokio::runtime::Runtime; | ||
|
||
use amadeus::prelude::*; | ||
|
||
static RT: Lazy<Runtime> = Lazy::new(|| { | ||
tokio::runtime::Builder::new() | ||
.threaded_scheduler() | ||
.enable_all() | ||
.build() | ||
.unwrap() | ||
}); | ||
static POOL: Lazy<ThreadPool> = Lazy::new(|| ThreadPool::new(None).unwrap()); | ||
|
||
#[bench] | ||
fn vec(b: &mut Bencher) { | ||
let rows: Vec<u32> = (0..1u32 << 28).collect(); | ||
let len = rows.len() as u64; | ||
let sum = len * (len - 1) / 2; | ||
let bytes = len * mem::size_of::<u32>() as u64; | ||
run(b, bytes, || async { | ||
assert_eq!( | ||
rows.par_stream() | ||
.map(|x| x as u64) | ||
.sum::<_, u64>(&*POOL) | ||
.await, | ||
sum | ||
); | ||
}) | ||
} | ||
|
||
#[bench] | ||
fn iter(b: &mut Bencher) { | ||
let rows: Vec<u32> = (0..1u32 << 28).collect(); | ||
let len = rows.len() as u64; | ||
let sum = len * (len - 1) / 2; | ||
let bytes = len * mem::size_of::<u32>() as u64; | ||
run(b, bytes, || async { | ||
assert_eq!(rows.iter().map(|&x| x as u64).sum::<u64>(), sum); | ||
}); | ||
} | ||
|
||
#[bench] | ||
fn rayon(b: &mut Bencher) { | ||
let rows: Vec<u32> = (0..1u32 << 28).collect(); | ||
let len = rows.len() as u64; | ||
let sum = len * (len - 1) / 2; | ||
let bytes = len * mem::size_of::<u32>() as u64; | ||
run(b, bytes, || async { | ||
assert_eq!(rows.par_iter().map(|&x| x as u64).sum::<u64>(), sum); | ||
}); | ||
} | ||
|
||
fn run<F>(b: &mut Bencher, bytes: u64, mut task: impl FnMut() -> F) | ||
where | ||
F: Future<Output = ()>, | ||
{ | ||
RT.enter(|| { | ||
let _ = Lazy::force(&POOL); | ||
b.bytes = bytes; | ||
b.iter(|| RT.handle().block_on(task())) | ||
}) | ||
} |
Oops, something went wrong.