This repository was archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbenchmarks.rs
238 lines (220 loc) · 7.1 KB
/
benchmarks.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use fastq_set::read_pair_iter::ReadPairIter;
use std::process::Command;
fn simple_count(file: impl ToString) -> usize {
let stdout = String::from_utf8(
Command::new("wc")
.arg("-l")
.arg(file.to_string())
.output()
.unwrap()
.stdout
.split(|x| *x == b' ')
.next()
.unwrap()
.to_vec(),
)
.unwrap();
stdout.trim().parse::<usize>().unwrap()
}
fn lz4_count(file: impl ToString) -> usize {
let stdout = String::from_utf8(
Command::new("sh")
.arg("lz4_wc.sh")
.arg(file.to_string())
.output()
.unwrap()
.stdout,
)
.unwrap();
stdout.trim().parse::<usize>().unwrap()
}
fn gz_count(file: impl ToString) -> usize {
let stdout = String::from_utf8(
Command::new("sh")
.arg("gz_wc.sh")
.arg(file.to_string())
.output()
.unwrap()
.stdout,
)
.unwrap();
stdout.trim().parse::<usize>().unwrap()
}
fn read_pair_count(file: impl ToString) -> usize {
let rp_iter = ReadPairIter::new(Some(file.to_string()), None, None, None, true).unwrap();
rp_iter.count()
}
// fn rna_chunk_iter_count(chemistry: ChemistryDef, file: impl ToString) -> usize {
// let chunk = RnaChunk::new(
// chemistry,
// 1,
// InputFastqs {
// r1: file.to_string(),
// r2: None,
// i1: None,
// i2: None,
// r1_interleaved: true,
// },
// "my_group".into(),
// );
// chunk.iter().unwrap().count()
// }
// fn rna_read_trim(
// chemistry: ChemistryDef,
// fastq_file: impl ToString,
// adapter_map: &HashMap<WhichRead, Vec<Adapter>>,
// ) -> usize {
// let mut ad_catalog = ReadAdapterCatalog::from(adapter_map);
// let chunk = RnaChunk::new(
// chemistry,
// 1,
// InputFastqs {
// r1: fastq_file.to_string(),
// r2: None,
// i1: None,
// i2: None,
// r1_interleaved: true,
// },
// "my_group".into(),
// );
// let mut ntrimmed = 0;
// for rna_read_result in chunk.iter().unwrap() {
// let mut rna_read = rna_read_result.unwrap();
// let adapter_positions = rna_read.trim_adapters(&mut ad_catalog);
// if !adapter_positions.is_empty() {
// ntrimmed += 1;
// }
// }
// ntrimmed
// }
// fn cutadapt_trim(fastq_file: impl ToString) -> bool {
// Command::new("sh")
// .arg("time_cutadapt.sh")
// .arg(fastq_file.to_string())
// .status()
// .is_ok()
// }
const INTERLEAVED_LZ4_FASTQ: &str = "tests/rna_read/interleaved_2k.fastq.lz4";
const INTERLEAVED_GZ_FASTQ: &str = "tests/rna_read/interleaved_2k.fastq.gz";
const INTERLEAVED_FASTQ: &str = "tests/rna_read/interleaved_2k.fastq";
// const INTERLEAVED_FASTQ_INSERT: &'static str = "tests/rna_read/interleaved_2k_insert.fastq";
fn run_fastq_lz4_benchmark(c: &mut Criterion) {
c.bench_function("bench-lz4-wc", |b| {
b.iter(
|| assert_eq!(lz4_count(INTERLEAVED_LZ4_FASTQ), 16000), // 16000 lines
);
});
c.bench_function("bench-lz4-read-pair-iter-count", |b| {
b.iter(
|| assert_eq!(read_pair_count(INTERLEAVED_LZ4_FASTQ), 2000), // 2000 read pairs
);
});
// let chemistry: ChemistryDef =
// serde_json::from_reader(File::open("tests/rna_read/sc_vdj_chemistry.json").unwrap())
// .unwrap();
// c.bench_function("bench-lz4-rna-chunk-iter-count", move |b| {
// b.iter(
// || {
// assert_eq!(
// rna_chunk_iter_count(chemistry.clone(), INTERLEAVED_LZ4_FASTQ),
// 2000
// )
// }, // 2000 read pairs
// )
// });
}
fn run_fastq_gz_benchmark(c: &mut Criterion) {
c.bench_function("bench-gz-wc", |b| {
b.iter(
|| assert_eq!(gz_count(INTERLEAVED_GZ_FASTQ), 16000), // 16000 lines
);
});
c.bench_function("bench-gz-read-pair-iter-count", |b| {
b.iter(
|| assert_eq!(read_pair_count(INTERLEAVED_GZ_FASTQ), 2000), // 2000 read pairs
);
});
// let chemistry: ChemistryDef =
// serde_json::from_reader(File::open("tests/rna_read/sc_vdj_chemistry.json").unwrap())
// .unwrap();
// c.bench_function("bench-gz-rna-chunk-iter-count", move |b| {
// b.iter(
// || {
// assert_eq!(
// rna_chunk_iter_count(chemistry.clone(), INTERLEAVED_GZ_FASTQ),
// 2000
// )
// }, // 2000 read pairs
// )
// });
}
fn run_fastq_benchmark(c: &mut Criterion) {
c.bench_function("bench-fastq-wc", |b| {
b.iter(
|| assert_eq!(simple_count(INTERLEAVED_FASTQ), 16000), // 16000 lines
);
});
c.bench_function("bench-fastq-read-pair-iter-count", |b| {
b.iter(
|| assert_eq!(read_pair_count(INTERLEAVED_FASTQ), 2000), // 2000 read pairs
);
});
// let chemistry: ChemistryDef =
// serde_json::from_reader(File::open("tests/rna_read/sc_vdj_chemistry.json").unwrap())
// .unwrap();
// c.bench_function("bench-fastq-rna-chunk-iter-count", move |b| {
// b.iter(
// || {
// assert_eq!(
// rna_chunk_iter_count(chemistry.clone(), INTERLEAVED_FASTQ),
// 2000
// )
// }, // 2000 read pairs
// )
// });
}
// fn run_trim_benchmark(c: &mut Criterion) {
// let chemistry: ChemistryDef =
// serde_json::from_reader(File::open("tests/rna_read/sc_vdj_chemistry.json").unwrap())
// .unwrap();
// let vdj_adapters: HashMap<WhichRead, Vec<Adapter>> =
// serde_json::from_reader(File::open("tests/rna_read/vdj_adapters.json").unwrap()).unwrap();
// c.bench(
// "bench-read-trim",
// Benchmark::new("rust-utils", move |b| {
// b.iter(|| rna_read_trim(chemistry.clone(), INTERLEAVED_FASTQ, &vdj_adapters))
// })
// .with_function("cutadapt", |b| {
// b.iter(|| assert!(cutadapt_trim(INTERLEAVED_FASTQ_INSERT)))
// })
// .sample_size(10)
// .throughput(Throughput::Elements(2000)),
// );
// }
fn sseq_serde_bincode(c: &mut Criterion) {
c.bench_function("bench-sseq-serde", |b| {
let seq = b"AGCTAGTCAGTCAGTA";
let mut sseqs = Vec::new();
for _i in 0..10_000 {
let s = fastq_set::sseq::SSeq::from_bytes(seq);
sseqs.push(s);
}
b.iter(|| {
let mut b = Vec::new();
bincode::serialize_into(&mut b, &sseqs).unwrap();
assert!(!b.is_empty());
});
});
}
criterion_group!(
benches,
run_fastq_lz4_benchmark,
run_fastq_benchmark,
run_fastq_gz_benchmark,
// run_trim_benchmark,
sseq_serde_bincode,
);
criterion_main!(benches);