Skip to content

Commit af5ea94

Browse files
committed
Use into_iter instead of iter.
It's slightly faster. On a huge file, old: ``` Benchmark 1: target/release/counts big2 > /dev/null Time (mean ± σ): 942.4 ms ± 21.1 ms [User: 884.6 ms, System: 57.7 ms] Range (min … max): 917.7 ms … 971.3 ms 10 runs ``` and new: ``` Benchmark 1: target/release/counts big2 > /dev/null Time (mean ± σ): 932.6 ms ± 14.2 ms [User: 874.2 ms, System: 58.4 ms] Range (min … max): 902.8 ms … 952.0 ms 10 runs ```
1 parent 34ddb11 commit af5ea94

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ where
158158

159159
// Sort from highest count to lowest count. For lines with the same count,
160160
// sort them in alphabetical order.
161-
let mut counts: Vec<_> = counts.iter().collect();
161+
let mut counts: Vec<_> = counts.into_iter().collect();
162162
counts.sort_unstable_by(|(line1, n1), (line2, n2)| {
163163
(n2.abs(), line1).partial_cmp(&(n1.abs(), line2)).unwrap()
164164
});
165165

166166
writeln!(io::stdout(), "{:.1} counts{}", total, label)?;
167167
let mut cum_perc: f64 = 0f64;
168168
let total_f64 = total.into_f64();
169-
for (i, (line, &weight)) in counts.iter().enumerate() {
169+
for (i, (line, weight)) in counts.iter().enumerate() {
170170
let perc: f64 = weight.into_f64() * 100f64 / total_f64;
171171
cum_perc += perc;
172172
writeln!(

0 commit comments

Comments
 (0)