History

[hours-demo] try sequential version - it's 2.5times slower

So rayon doesn't give perfect scaling here, but it's worth it.

Sebastian Thiel committed 5 years ago

Commit d166cf11 parent 32452451 file · +7 −17Browse files

Unified · Split

demos/hours/src/main.rs+7−17
@@ -72,30 +72,20 @@ fn main() -> anyhow::Result<()> { · 71 unmodified lines
72 72
73 eprintln!("Getting all commit data…");73 eprintln!("Getting all commit data…");
74 let start = Instant::now();74 let start = Instant::now();
75 let commits_wanted = all_commits.len();
75 #[allow(clippy::redundant_closure)]76 #[allow(clippy::redundant_closure)]
76 let mut all_commits: Vec<CommitInfo> = all_commits77 let mut all_commits: Vec<CommitInfo> = all_commits
77 .into_par_iter()78 .into_iter()
78 .map(|commit_data: Vec<u8>| {79 .filter_map(|commit_data: Vec<u8>| {
79 git_object::immutable::CommitIter::from_bytes(&commit_data)80 git_object::immutable::CommitIter::from_bytes(&commit_data)
80 .signatures()81 .signatures()
81 .next()82 .next()
82 .map(|author| git_object::mutable::Signature::from(author))83 .map(|author| git_object::mutable::Signature::from(author))
83 })84 })
84 .try_fold(85 .collect::<Vec<_>>();
85 || Vec::new(),86 if all_commits.len() != commits_wanted {
86 |mut out: Vec<_>, item| {87 bail!("An error occurred when decoding commits - one commit could not be parsed");
87 out.push(item?);88 }
88 Some(out)
89 },
90 )
91 .try_reduce(
92 || Vec::new(),
93 |mut out, vec| {
94 out.extend(vec.into_iter());
95 Some(out)
96 },
97 )
98 .ok_or_else(|| anyhow!("An error occurred when decoding commits - one commit could not be parsed"))?;
99 let elapsed = start.elapsed();89 let elapsed = start.elapsed();
100 eprintln!(90 eprintln!(
101 "Obtained {} commits in {:?} ({:0.0} commits/s)",91 "Obtained {} commits in {:?} ({:0.0} commits/s)",