From fb2dda8491d40630bb20437483b76f80ee1145f8 Mon Sep 17 00:00:00 2001 From: Naveen Naidu Date: Mon, 6 May 2024 16:07:49 +0530 Subject: [PATCH] Apporach 2: Remove redundant creation of Vector while reading line (Time: 241s) In the 'read_line' function, we split the line at ';' and then collect the split data into a vector. This collection is redundant because we discard this vector at the end of function. The 'collect()' call has to make a system call to allocate some memory on heap, and since we do this for 1 billion lines - the extra overhead time for creating space for vector accumulates. Instead of using 'collect()' we only split the line and use the interators to extract the values. This removes the necessity of talking to the OS. --- flamegraph.svg | 491 ++++++++++++++++++ .../flamegraph.svg | 491 ++++++++++++++++++ src/main.rs | 8 +- 3 files changed, 986 insertions(+), 4 deletions(-) create mode 100644 flamegraph.svg create mode 100644 flamegraphs/02-Use-iterator-instead-of-collect-read-line/flamegraph.svg diff --git a/flamegraph.svg b/flamegraph.svg new file mode 100644 index 0000000..4e24786 --- /dev/null +++ b/flamegraph.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch core::array::_<impl core::ops::index::Index<I> for [T: N]>::index (19 samples, 0.02%)core::slice::index::<impl core::ops::index::Index<I> for [T]>::index (19 samples, 0.02%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index (19 samples, 0.02%)core::cmp::impls::<impl core::cmp::PartialEq<&B> for &A>::eq (2,163 samples, 1.71%)core::slice::cmp::<impl core::cmp::PartialEq<[B]> for [A]>::eq (2,163 samples, 1.71%)<[A] as core::slice::cmp::SlicePartialEq<B>>::equal (2,163 samples, 1.71%)[libc.so.6] (1,773 samples, 1.40%)core::slice::<impl [T]>::get (262 samples, 0.21%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::get (262 samples, 0.21%)core::num::<impl usize>::repeat_u8 (305 samples, 0.24%)core::ptr::const_ptr::<impl *const T>::align_offset (556 samples, 0.44%)core::ptr::align_offset (556 samples, 0.44%)core::slice::memchr::contains_zero_byte (755 samples, 0.60%)core::num::<impl usize>::wrapping_sub (249 samples, 0.20%)core::slice::memchr::memchr_aligned (213 samples, 0.17%)<core::str::pattern::CharSearcher as core::str::pattern::Searcher>::next_match (22,303 samples, 17.63%)<core::str::pattern::CharSe..core::slice::memchr::memchr (15,805 samples, 12.49%)core::slice::memchr..core::slice::memchr::memchr_aligned (15,746 samples, 12.45%)core::slice::memchr..core::slice::memchr::memchr_naive (5,950 samples, 4.70%)core:..<core::str::iter::SplitInclusive<P> as core::iter::traits::iterator::Iterator>::next (24,847 samples, 19.64%)<core::str::iter::SplitInclusiv..core::str::iter::SplitInternal<P>::next_inclusive (24,847 samples, 19.64%)core::str::iter::SplitInternal<..<core::str::LinesMap as core::ops::function::Fn<(&str,)>>::call (570 samples, 0.45%)core::str::<impl str>::strip_suffix (105 samples, 0.08%)<char as core::str::pattern::Pattern>::strip_suffix_of (105 samples, 0.08%)<&str as core::str::pattern::Pattern>::strip_suffix_of (105 samples, 0.08%)<&str as core::str::pattern::Pattern>::is_suffix_of (105 samples, 0.08%)core::slice::<impl [T]>::ends_with (105 samples, 0.08%)<core::str::iter::Lines as core::iter::traits::iterator::Iterator>::next (25,758 samples, 20.36%)<core::str::iter::Lines as core:..<core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next (25,758 samples, 20.36%)<core::iter::adapters::map::Map<..core::option::Option<T>::map (911 samples, 0.72%)core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once (911 samples, 0.72%)<core::str::LinesMap as core::ops::function::FnMut<(&str,)>>::call_mut (911 samples, 0.72%)rust_1brc::main (341 samples, 0.27%)__rdl_alloc (263 samples, 0.21%)__rust_alloc (909 samples, 0.72%)alloc::vec::Vec<T,A>::with_capacity_in (8,714 samples, 6.89%)alloc::ve..alloc::raw_vec::RawVec<T,A>::with_capacity_in (8,714 samples, 6.89%)alloc::ra..alloc::raw_vec::RawVec<T,A>::allocate_in (8,714 samples, 6.89%)alloc::ra..<alloc::alloc::Global as core::alloc::Allocator>::allocate (8,642 samples, 6.83%)<alloc::a..alloc::alloc::Global::alloc_impl (8,642 samples, 6.83%)alloc::al..alloc::alloc::alloc (8,642 samples, 6.83%)alloc::al..malloc (5,447 samples, 4.31%)malloc<str as alloc::string::ToString>::to_string (9,900 samples, 7.83%)<str as all..<alloc::string::String as core::convert::From<&str>>::from (9,900 samples, 7.83%)<alloc::str..alloc::str::<impl alloc::borrow::ToOwned for str>::to_owned (9,900 samples, 7.83%)alloc::str:..alloc::slice::<impl alloc::borrow::ToOwned for [T]>::to_owned (9,900 samples, 7.83%)alloc::slic..alloc::slice::<impl [T]>::to_vec (9,900 samples, 7.83%)alloc::slic..alloc::slice::<impl [T]>::to_vec_in (9,900 samples, 7.83%)alloc::slic..alloc::slice::hack::to_vec (9,900 samples, 7.83%)alloc::slic..<T as alloc::slice::hack::ConvertVec>::to_vec (9,900 samples, 7.83%)<T as alloc..core::ptr::const_ptr::<impl *const T>::copy_to_nonoverlapping (1,186 samples, 0.94%)core::intrinsics::copy_nonoverlapping (1,186 samples, 0.94%)[libc.so.6] (1,185 samples, 0.94%)<F as core::str::pattern::Pattern>::into_searcher (134 samples, 0.11%)<core::str::pattern::MultiCharEqPattern<C> as core::str::pattern::Pattern>::into_searcher (134 samples, 0.11%)core::str::<impl str>::char_indices (134 samples, 0.11%)core::str::<impl str>::chars (134 samples, 0.11%)core::slice::<impl [T]>::iter (134 samples, 0.11%)core::slice::iter::Iter<T>::new (134 samples, 0.11%)core::str::<impl str>::trim_matches (134 samples, 0.11%)<F as core::str::pattern::MultiCharEq>::matches (341 samples, 0.27%)core::str::_<impl str>::trim::_{{closure}} (341 samples, 0.27%)core::char::methods::<impl char>::is_whitespace (341 samples, 0.27%)<core::str::pattern::MultiCharEqSearcher<C> as core::str::pattern::ReverseSearcher>::next_back (939 samples, 0.74%)<core::str::iter::CharIndices as core::iter::traits::double_ended::DoubleEndedIterator>::next_back (598 samples, 0.47%)<core::str::iter::Chars as core::iter::traits::double_ended::DoubleEndedIterator>::next_back (598 samples, 0.47%)core::str::validations::next_code_point_reverse (598 samples, 0.47%)<core::str::pattern::CharPredicateSearcher<F> as core::str::pattern::ReverseSearcher>::next_reject_back (1,103 samples, 0.87%)core::str::pattern::ReverseSearcher::next_reject_back (1,103 samples, 0.87%)core::str::<impl str>::trim_matches (164 samples, 0.13%)<F as core::str::pattern::MultiCharEq>::matches (241 samples, 0.19%)core::str::_<impl str>::trim::_{{closure}} (241 samples, 0.19%)core::char::methods::<impl char>::is_whitespace (241 samples, 0.19%)<core::str::iter::CharIndices as core::iter::traits::iterator::Iterator>::next (122 samples, 0.10%)<core::str::iter::Chars as core::iter::traits::iterator::Iterator>::next (35 samples, 0.03%)core::str::validations::next_code_point (30 samples, 0.02%)core::str::validations::utf8_first_byte (14 samples, 0.01%)<core::str::pattern::MultiCharEqSearcher<C> as core::str::pattern::Searcher>::next (370 samples, 0.29%)<core::str::pattern::CharPredicateSearcher<F> as core::str::pattern::Searcher>::next_reject (475 samples, 0.38%)core::str::pattern::Searcher::next_reject (475 samples, 0.38%)core::str::<impl str>::trim_matches (105 samples, 0.08%)core::str::<impl str>::trim (2,473 samples, 1.95%)c..core::str::<impl str>::trim_matches (2,328 samples, 1.84%)c..core::str::<impl str>::get_unchecked (150 samples, 0.12%)core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::Range<usize>>::get_unchecked (150 samples, 0.12%)rust_1brc::main (78 samples, 0.06%)core::array::_<impl core::ops::index::Index<I> for [T: N]>::index (141 samples, 0.11%)core::slice::index::<impl core::ops::index::Index<I> for [T]>::index (141 samples, 0.11%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index (141 samples, 0.11%)[libc.so.6] (1,304 samples, 1.03%)core::cmp::impls::<impl core::cmp::PartialEq<&B> for &A>::eq (1,861 samples, 1.47%)core::slice::cmp::<impl core::cmp::PartialEq<[B]> for [A]>::eq (1,861 samples, 1.47%)<[A] as core::slice::cmp::SlicePartialEq<B>>::equal (1,861 samples, 1.47%)core::slice::<impl [T]>::get (1,290 samples, 1.02%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::get (1,290 samples, 1.02%)core::num::<impl usize>::repeat_u8 (37 samples, 0.03%)core::ptr::const_ptr::<impl *const T>::align_offset (79 samples, 0.06%)core::ptr::align_offset (79 samples, 0.06%)core::slice::memchr::contains_zero_byte (122 samples, 0.10%)core::num::<impl usize>::wrapping_sub (36 samples, 0.03%)core::slice::memchr::memchr_aligned (1,601 samples, 1.27%)core::slice::memchr::memchr_naive (748 samples, 0.59%)<core::str::pattern::CharSearcher as core::str::pattern::Searcher>::next_match (16,647 samples, 13.16%)<core::str::pattern:..core::slice::memchr::memchr (6,573 samples, 5.20%)core::..core::slice::memchr::memchr_naive (4,581 samples, 3.62%)core..core::str::iter::SplitInternal<P>::get_end (295 samples, 0.23%)core::str::<impl str>::get_unchecked (15 samples, 0.01%)core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::Range<usize>>::get_unchecked (15 samples, 0.01%)<core::str::iter::Split<P> as core::iter::traits::iterator::Iterator>::next (19,662 samples, 15.54%)<core::str::iter::Split<..core::str::iter::SplitInternal<P>::next (19,662 samples, 15.54%)core::str::iter::SplitIn..rust_1brc::main (548 samples, 0.43%)__rdl_alloc (279 samples, 0.22%)__rust_alloc (268 samples, 0.21%)alloc::vec::Vec<T,A>::with_capacity_in (2,971 samples, 2.35%)a..alloc::raw_vec::RawVec<T,A>::with_capacity_in (2,971 samples, 2.35%)a..alloc::raw_vec::RawVec<T,A>::allocate_in (2,971 samples, 2.35%)a..<alloc::alloc::Global as core::alloc::Allocator>::allocate (2,960 samples, 2.34%)<..alloc::alloc::Global::alloc_impl (2,960 samples, 2.34%)a..alloc::alloc::alloc (2,960 samples, 2.34%)a..malloc (1,427 samples, 1.13%)<T as alloc::slice::hack::ConvertVec>::to_vec (4,118 samples, 3.26%)<T ..core::ptr::const_ptr::<impl *const T>::copy_to_nonoverlapping (1,147 samples, 0.91%)core::intrinsics::copy_nonoverlapping (1,147 samples, 0.91%)[libc.so.6] (897 samples, 0.71%)alloc::str::<impl alloc::borrow::ToOwned for str>::to_owned (4,149 samples, 3.28%)all..alloc::slice::<impl alloc::borrow::ToOwned for [T]>::to_owned (4,149 samples, 3.28%)all..alloc::slice::<impl [T]>::to_vec (4,149 samples, 3.28%)all..alloc::slice::<impl [T]>::to_vec_in (4,149 samples, 3.28%)all..alloc::slice::hack::to_vec (4,149 samples, 3.28%)all..rust_1brc::main (31 samples, 0.02%)__rdl_dealloc (270 samples, 0.21%)__rust_dealloc (536 samples, 0.42%)[libc.so.6] (4,262 samples, 3.37%)[li..<alloc::alloc::Global as core::alloc::Allocator>::deallocate (6,372 samples, 5.04%)<alloc..alloc::alloc::dealloc (6,372 samples, 5.04%)alloc:..cfree (5,566 samples, 4.40%)cfreecore::ptr::drop_in_place<alloc::string::String> (6,374 samples, 5.04%)core::..core::ptr::drop_in_place<alloc::vec::Vec<u8>> (6,374 samples, 5.04%)core::..core::ptr::drop_in_place<alloc::raw_vec::RawVec<u8>> (6,374 samples, 5.04%)core::..<alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop (6,374 samples, 5.04%)<alloc..core::result::Result<T,E>::expect (275 samples, 0.22%)core::num::dec2flt::<impl core::str::traits::FromStr for f32>::from_str (274 samples, 0.22%)<f32 as core::num::dec2flt::float::RawFloat>::pow10_fast_path (44 samples, 0.03%)<f32 as core::ops::arith::Div>::div (3,896 samples, 3.08%)<f3..core::num::dec2flt::number::Number::try_fast_path (4,425 samples, 3.50%)cor..core::num::dec2flt::number::Number::is_fast_path (199 samples, 0.16%)core::num::dec2flt::parse::parse_number (89 samples, 0.07%)core::num::<impl u8>::wrapping_sub (25 samples, 0.02%)<[u8] as core::num::dec2flt::common::ByteSlice>::parse_digits (2,097 samples, 1.66%)core::num::dec2flt::parse::try_parse_digits::_{{closure}} (197 samples, 0.16%)core::num::dec2flt::parse::try_parse_digits (3,597 samples, 2.84%)co..core::num::dec2flt::parse::parse_number (249 samples, 0.20%)core::num::dec2flt::parse::parse_number (7,746 samples, 6.12%)core::nu..core::num::dec2flt::parse::parse_partial_number (4,460 samples, 3.53%)cor..core::str::<impl str>::parse (15,153 samples, 11.98%)core::str::<impl s..core::num::dec2flt::<impl core::str::traits::FromStr for f32>::from_str (15,050 samples, 11.90%)core::num::dec2flt..core::num::dec2flt::dec2flt (14,214 samples, 11.24%)core::num::dec2fl..core::slice::<impl [T]>::first (264 samples, 0.21%)rust_1brc::read_line (46,204 samples, 36.52%)rust_1brc::read_linecore::str::<impl str>::split (591 samples, 0.47%)std::collections::hash::map::Entry<K,V>::and_modify (723 samples, 0.57%)rust_1brc::calculate_station_values::_{{closure}} (723 samples, 0.57%)__rdl_dealloc (296 samples, 0.23%)__rust_dealloc (362 samples, 0.29%)alloc::alloc::dealloc (3,707 samples, 2.93%)al..cfree (2,889 samples, 2.28%)c..[libc.so.6] (2,038 samples, 1.61%)std::collections::hash::map::Entry<K,V>::or_insert (3,741 samples, 2.96%)std..std::collections::hash::map::OccupiedEntry<K,V>::into_mut (3,741 samples, 2.96%)std..hashbrown::rustc_entry::RustcOccupiedEntry<K,V,A>::into_mut (3,741 samples, 2.96%)has..core::ptr::drop_in_place<hashbrown::rustc_entry::RustcOccupiedEntry<alloc::string::String,rust_1brc::StationValues>> (3,741 samples, 2.96%)cor..core::ptr::drop_in_place<core::option::Option<alloc::string::String>> (3,741 samples, 2.96%)cor..core::ptr::drop_in_place<alloc::string::String> (3,720 samples, 2.94%)co..core::ptr::drop_in_place<alloc::vec::Vec<u8>> (3,720 samples, 2.94%)co..core::ptr::drop_in_place<alloc::raw_vec::RawVec<u8>> (3,720 samples, 2.94%)co..<alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop (3,720 samples, 2.94%)<a..<alloc::alloc::Global as core::alloc::Allocator>::deallocate (3,720 samples, 2.94%)<a..rust_1brc::main (13 samples, 0.01%)core::num::<impl u64>::rotate_left (576 samples, 0.46%)<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::c_rounds (1,380 samples, 1.09%)core::num::<impl u64>::wrapping_add (280 samples, 0.22%)core::num::<impl u64>::rotate_left (2,839 samples, 2.24%)c..<core::hash::sip::Hasher<S> as core::hash::Hasher>::finish (6,341 samples, 5.01%)<core:..<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::d_rounds (3,925 samples, 3.10%)<co..core::num::<impl u64>::wrapping_add (507 samples, 0.40%)<std::hash::random::DefaultHasher as core::hash::Hasher>::finish (7,888 samples, 6.24%)<std::ha..<core::hash::sip::SipHasher13 as core::hash::Hasher>::finish (7,888 samples, 6.24%)<core::h..core::hash::BuildHasher::hash_one (1,547 samples, 1.22%)<std::hash::random::RandomState as core::hash::BuildHasher>::build_hasher (620 samples, 0.49%)core::hash::sip::SipHasher13::new_with_keys (361 samples, 0.29%)core::hash::sip::Hasher<S>::new_with_keys (361 samples, 0.29%)core::hash::sip::Hasher<S>::reset (361 samples, 0.29%)core::hash::BuildHasher::hash_one (76 samples, 0.06%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (21 samples, 0.02%)core::num::<impl u64>::rotate_left (415 samples, 0.33%)<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::c_rounds (676 samples, 0.53%)core::num::<impl u64>::wrapping_add (149 samples, 0.12%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (26 samples, 0.02%)core::hash::sip::u8to64_le (803 samples, 0.63%)core::intrinsics::copy_nonoverlapping (57 samples, 0.05%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (3,817 samples, 3.02%)<co..core::intrinsics::copy_nonoverlapping (17 samples, 0.01%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (14 samples, 0.01%)core::num::<impl u64>::rotate_left (92 samples, 0.07%)<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::c_rounds (266 samples, 0.21%)core::num::<impl u64>::wrapping_add (90 samples, 0.07%)core::cmp::min (189 samples, 0.15%)core::cmp::Ord::min (189 samples, 0.15%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (189 samples, 0.15%)hashbrown::map::make_hash (16,561 samples, 13.09%)hashbrown::map::make..core::hash::BuildHasher::hash_one (16,470 samples, 13.02%)core::hash::BuildHas..core::hash::impls::<impl core::hash::Hash for &T>::hash (7,557 samples, 5.97%)core::ha..<alloc::string::String as core::hash::Hash>::hash (7,501 samples, 5.93%)<alloc::..core::hash::impls::<impl core::hash::Hash for str>::hash (7,501 samples, 5.93%)core::ha..<std::hash::random::DefaultHasher as core::hash::Hasher>::write_str (7,501 samples, 5.93%)<std::ha..<core::hash::sip::SipHasher13 as core::hash::Hasher>::write_str (7,501 samples, 5.93%)<core::h..<core::hash::sip::Hasher<S> as core::hash::Hasher>::write_str (7,501 samples, 5.93%)<core::h..core::hash::Hasher::write_u8 (3,619 samples, 2.86%)co..<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (3,375 samples, 2.67%)<c..core::hash::sip::u8to64_le (927 samples, 0.73%)core::num::nonzero::NonZero<u16>::new (32 samples, 0.03%)<hashbrown::raw::bitmask::BitMaskIter as core::iter::traits::iterator::Iterator>::next (35 samples, 0.03%)hashbrown::raw::bitmask::BitMask::lowest_set_bit (35 samples, 0.03%)hashbrown::raw::RawTable<T,A>::bucket (547 samples, 0.43%)hashbrown::raw::Bucket<T>::from_base_index (547 samples, 0.43%)core::ptr::mut_ptr::<impl *mut T>::sub (547 samples, 0.43%)core::ptr::mut_ptr::<impl *mut T>::offset (277 samples, 0.22%)hashbrown::raw::RawTable<T,A>::find::_{{closure}} (9,752 samples, 7.71%)hashbrown::..hashbrown::rustc_entry::_<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry::_{{closure}} (9,204 samples, 7.28%)hashbrown:..<alloc::string::String as core::cmp::PartialEq>::eq (9,204 samples, 7.28%)<alloc::st..alloc::vec::partial_eq::<impl core::cmp::PartialEq<alloc::vec::Vec<U,A2>> for alloc::vec::Vec<T,A1>>::eq (9,204 samples, 7.28%)alloc::vec..core::slice::cmp::<impl core::cmp::PartialEq<[B]> for [A]>::eq (9,204 samples, 7.28%)core::slic..<[A] as core::slice::cmp::SlicePartialEq<B>>::equal (9,204 samples, 7.28%)<[A] as co..[libc.so.6] (6,225 samples, 4.92%)[libc...hashbrown::raw::h2 (1,988 samples, 1.57%)hashbrown::raw::sse2::Group::load (87 samples, 0.07%)core::core_arch::x86::sse2::_mm_loadu_si128 (87 samples, 0.07%)hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (84 samples, 0.07%)hashbrown::raw::sse2::Group::match_byte (2,523 samples, 1.99%)h..core::core_arch::x86::sse2::_mm_movemask_epi8 (2,523 samples, 1.99%)c..hashbrown::raw::sse2::Group::match_empty (323 samples, 0.26%)hashbrown::raw::sse2::Group::match_byte (323 samples, 0.26%)core::core_arch::x86::sse2::_mm_movemask_epi8 (323 samples, 0.26%)hashbrown::raw::RawTableInner::find_inner (16,965 samples, 13.41%)hashbrown::raw::RawT..hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (390 samples, 0.31%)hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (35,084 samples, 27.73%)hashbrown::rustc_entry::<impl hashbrown::map:..hashbrown::raw::RawTable<T,A>::find (16,989 samples, 13.43%)hashbrown::raw::RawT..hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (22 samples, 0.02%)rust_1brc::main (533 samples, 0.42%)rust_1brc::calculate_station_values (124,959 samples, 98.78%)rust_1brc::calculate_station_valuesstd::collections::hash::map::HashMap<K,V,S>::entry (36,056 samples, 28.50%)std::collections::hash::map::HashMap<K,V,S>::e..std::collections::hash::map::map_entry (201 samples, 0.16%)rust_1brc::main (212 samples, 0.17%)core::str::converts::from_utf8 (1,306 samples, 1.03%)core::str::validations::run_utf8_validation (1,305 samples, 1.03%)core::str::validations::utf8_char_width (74 samples, 0.06%)all (126,508 samples, 100%)rust-1brc (126,508 samples, 100.00%)rust-1brc_start (126,501 samples, 99.99%)_start__libc_start_main (126,501 samples, 99.99%)__libc_start_main[libc.so.6] (126,501 samples, 99.99%)[libc.so.6]main (126,501 samples, 99.99%)mainstd::rt::lang_start_internal (126,501 samples, 99.99%)std::rt::lang_start_internalstd::rt::lang_start::_{{closure}} (126,501 samples, 99.99%)std::rt::lang_start::_{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (126,501 samples, 99.99%)std::sys_common::backtrace::__rust_begin_short_backtracecore::ops::function::FnOnce::call_once (126,501 samples, 99.99%)core::ops::function::FnOnce::call_oncerust_1brc::main (126,501 samples, 99.99%)rust_1brc::mainstd::fs::read_to_string (1,329 samples, 1.05%)std::fs::read_to_string::inner (1,329 samples, 1.05%)std::io::default_read_to_end (23 samples, 0.02%) \ No newline at end of file diff --git a/flamegraphs/02-Use-iterator-instead-of-collect-read-line/flamegraph.svg b/flamegraphs/02-Use-iterator-instead-of-collect-read-line/flamegraph.svg new file mode 100644 index 0000000..4e24786 --- /dev/null +++ b/flamegraphs/02-Use-iterator-instead-of-collect-read-line/flamegraph.svg @@ -0,0 +1,491 @@ +Flame Graph Reset ZoomSearch core::array::_<impl core::ops::index::Index<I> for [T: N]>::index (19 samples, 0.02%)core::slice::index::<impl core::ops::index::Index<I> for [T]>::index (19 samples, 0.02%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index (19 samples, 0.02%)core::cmp::impls::<impl core::cmp::PartialEq<&B> for &A>::eq (2,163 samples, 1.71%)core::slice::cmp::<impl core::cmp::PartialEq<[B]> for [A]>::eq (2,163 samples, 1.71%)<[A] as core::slice::cmp::SlicePartialEq<B>>::equal (2,163 samples, 1.71%)[libc.so.6] (1,773 samples, 1.40%)core::slice::<impl [T]>::get (262 samples, 0.21%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::get (262 samples, 0.21%)core::num::<impl usize>::repeat_u8 (305 samples, 0.24%)core::ptr::const_ptr::<impl *const T>::align_offset (556 samples, 0.44%)core::ptr::align_offset (556 samples, 0.44%)core::slice::memchr::contains_zero_byte (755 samples, 0.60%)core::num::<impl usize>::wrapping_sub (249 samples, 0.20%)core::slice::memchr::memchr_aligned (213 samples, 0.17%)<core::str::pattern::CharSearcher as core::str::pattern::Searcher>::next_match (22,303 samples, 17.63%)<core::str::pattern::CharSe..core::slice::memchr::memchr (15,805 samples, 12.49%)core::slice::memchr..core::slice::memchr::memchr_aligned (15,746 samples, 12.45%)core::slice::memchr..core::slice::memchr::memchr_naive (5,950 samples, 4.70%)core:..<core::str::iter::SplitInclusive<P> as core::iter::traits::iterator::Iterator>::next (24,847 samples, 19.64%)<core::str::iter::SplitInclusiv..core::str::iter::SplitInternal<P>::next_inclusive (24,847 samples, 19.64%)core::str::iter::SplitInternal<..<core::str::LinesMap as core::ops::function::Fn<(&str,)>>::call (570 samples, 0.45%)core::str::<impl str>::strip_suffix (105 samples, 0.08%)<char as core::str::pattern::Pattern>::strip_suffix_of (105 samples, 0.08%)<&str as core::str::pattern::Pattern>::strip_suffix_of (105 samples, 0.08%)<&str as core::str::pattern::Pattern>::is_suffix_of (105 samples, 0.08%)core::slice::<impl [T]>::ends_with (105 samples, 0.08%)<core::str::iter::Lines as core::iter::traits::iterator::Iterator>::next (25,758 samples, 20.36%)<core::str::iter::Lines as core:..<core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next (25,758 samples, 20.36%)<core::iter::adapters::map::Map<..core::option::Option<T>::map (911 samples, 0.72%)core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once (911 samples, 0.72%)<core::str::LinesMap as core::ops::function::FnMut<(&str,)>>::call_mut (911 samples, 0.72%)rust_1brc::main (341 samples, 0.27%)__rdl_alloc (263 samples, 0.21%)__rust_alloc (909 samples, 0.72%)alloc::vec::Vec<T,A>::with_capacity_in (8,714 samples, 6.89%)alloc::ve..alloc::raw_vec::RawVec<T,A>::with_capacity_in (8,714 samples, 6.89%)alloc::ra..alloc::raw_vec::RawVec<T,A>::allocate_in (8,714 samples, 6.89%)alloc::ra..<alloc::alloc::Global as core::alloc::Allocator>::allocate (8,642 samples, 6.83%)<alloc::a..alloc::alloc::Global::alloc_impl (8,642 samples, 6.83%)alloc::al..alloc::alloc::alloc (8,642 samples, 6.83%)alloc::al..malloc (5,447 samples, 4.31%)malloc<str as alloc::string::ToString>::to_string (9,900 samples, 7.83%)<str as all..<alloc::string::String as core::convert::From<&str>>::from (9,900 samples, 7.83%)<alloc::str..alloc::str::<impl alloc::borrow::ToOwned for str>::to_owned (9,900 samples, 7.83%)alloc::str:..alloc::slice::<impl alloc::borrow::ToOwned for [T]>::to_owned (9,900 samples, 7.83%)alloc::slic..alloc::slice::<impl [T]>::to_vec (9,900 samples, 7.83%)alloc::slic..alloc::slice::<impl [T]>::to_vec_in (9,900 samples, 7.83%)alloc::slic..alloc::slice::hack::to_vec (9,900 samples, 7.83%)alloc::slic..<T as alloc::slice::hack::ConvertVec>::to_vec (9,900 samples, 7.83%)<T as alloc..core::ptr::const_ptr::<impl *const T>::copy_to_nonoverlapping (1,186 samples, 0.94%)core::intrinsics::copy_nonoverlapping (1,186 samples, 0.94%)[libc.so.6] (1,185 samples, 0.94%)<F as core::str::pattern::Pattern>::into_searcher (134 samples, 0.11%)<core::str::pattern::MultiCharEqPattern<C> as core::str::pattern::Pattern>::into_searcher (134 samples, 0.11%)core::str::<impl str>::char_indices (134 samples, 0.11%)core::str::<impl str>::chars (134 samples, 0.11%)core::slice::<impl [T]>::iter (134 samples, 0.11%)core::slice::iter::Iter<T>::new (134 samples, 0.11%)core::str::<impl str>::trim_matches (134 samples, 0.11%)<F as core::str::pattern::MultiCharEq>::matches (341 samples, 0.27%)core::str::_<impl str>::trim::_{{closure}} (341 samples, 0.27%)core::char::methods::<impl char>::is_whitespace (341 samples, 0.27%)<core::str::pattern::MultiCharEqSearcher<C> as core::str::pattern::ReverseSearcher>::next_back (939 samples, 0.74%)<core::str::iter::CharIndices as core::iter::traits::double_ended::DoubleEndedIterator>::next_back (598 samples, 0.47%)<core::str::iter::Chars as core::iter::traits::double_ended::DoubleEndedIterator>::next_back (598 samples, 0.47%)core::str::validations::next_code_point_reverse (598 samples, 0.47%)<core::str::pattern::CharPredicateSearcher<F> as core::str::pattern::ReverseSearcher>::next_reject_back (1,103 samples, 0.87%)core::str::pattern::ReverseSearcher::next_reject_back (1,103 samples, 0.87%)core::str::<impl str>::trim_matches (164 samples, 0.13%)<F as core::str::pattern::MultiCharEq>::matches (241 samples, 0.19%)core::str::_<impl str>::trim::_{{closure}} (241 samples, 0.19%)core::char::methods::<impl char>::is_whitespace (241 samples, 0.19%)<core::str::iter::CharIndices as core::iter::traits::iterator::Iterator>::next (122 samples, 0.10%)<core::str::iter::Chars as core::iter::traits::iterator::Iterator>::next (35 samples, 0.03%)core::str::validations::next_code_point (30 samples, 0.02%)core::str::validations::utf8_first_byte (14 samples, 0.01%)<core::str::pattern::MultiCharEqSearcher<C> as core::str::pattern::Searcher>::next (370 samples, 0.29%)<core::str::pattern::CharPredicateSearcher<F> as core::str::pattern::Searcher>::next_reject (475 samples, 0.38%)core::str::pattern::Searcher::next_reject (475 samples, 0.38%)core::str::<impl str>::trim_matches (105 samples, 0.08%)core::str::<impl str>::trim (2,473 samples, 1.95%)c..core::str::<impl str>::trim_matches (2,328 samples, 1.84%)c..core::str::<impl str>::get_unchecked (150 samples, 0.12%)core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::Range<usize>>::get_unchecked (150 samples, 0.12%)rust_1brc::main (78 samples, 0.06%)core::array::_<impl core::ops::index::Index<I> for [T: N]>::index (141 samples, 0.11%)core::slice::index::<impl core::ops::index::Index<I> for [T]>::index (141 samples, 0.11%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index (141 samples, 0.11%)[libc.so.6] (1,304 samples, 1.03%)core::cmp::impls::<impl core::cmp::PartialEq<&B> for &A>::eq (1,861 samples, 1.47%)core::slice::cmp::<impl core::cmp::PartialEq<[B]> for [A]>::eq (1,861 samples, 1.47%)<[A] as core::slice::cmp::SlicePartialEq<B>>::equal (1,861 samples, 1.47%)core::slice::<impl [T]>::get (1,290 samples, 1.02%)<core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::get (1,290 samples, 1.02%)core::num::<impl usize>::repeat_u8 (37 samples, 0.03%)core::ptr::const_ptr::<impl *const T>::align_offset (79 samples, 0.06%)core::ptr::align_offset (79 samples, 0.06%)core::slice::memchr::contains_zero_byte (122 samples, 0.10%)core::num::<impl usize>::wrapping_sub (36 samples, 0.03%)core::slice::memchr::memchr_aligned (1,601 samples, 1.27%)core::slice::memchr::memchr_naive (748 samples, 0.59%)<core::str::pattern::CharSearcher as core::str::pattern::Searcher>::next_match (16,647 samples, 13.16%)<core::str::pattern:..core::slice::memchr::memchr (6,573 samples, 5.20%)core::..core::slice::memchr::memchr_naive (4,581 samples, 3.62%)core..core::str::iter::SplitInternal<P>::get_end (295 samples, 0.23%)core::str::<impl str>::get_unchecked (15 samples, 0.01%)core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::Range<usize>>::get_unchecked (15 samples, 0.01%)<core::str::iter::Split<P> as core::iter::traits::iterator::Iterator>::next (19,662 samples, 15.54%)<core::str::iter::Split<..core::str::iter::SplitInternal<P>::next (19,662 samples, 15.54%)core::str::iter::SplitIn..rust_1brc::main (548 samples, 0.43%)__rdl_alloc (279 samples, 0.22%)__rust_alloc (268 samples, 0.21%)alloc::vec::Vec<T,A>::with_capacity_in (2,971 samples, 2.35%)a..alloc::raw_vec::RawVec<T,A>::with_capacity_in (2,971 samples, 2.35%)a..alloc::raw_vec::RawVec<T,A>::allocate_in (2,971 samples, 2.35%)a..<alloc::alloc::Global as core::alloc::Allocator>::allocate (2,960 samples, 2.34%)<..alloc::alloc::Global::alloc_impl (2,960 samples, 2.34%)a..alloc::alloc::alloc (2,960 samples, 2.34%)a..malloc (1,427 samples, 1.13%)<T as alloc::slice::hack::ConvertVec>::to_vec (4,118 samples, 3.26%)<T ..core::ptr::const_ptr::<impl *const T>::copy_to_nonoverlapping (1,147 samples, 0.91%)core::intrinsics::copy_nonoverlapping (1,147 samples, 0.91%)[libc.so.6] (897 samples, 0.71%)alloc::str::<impl alloc::borrow::ToOwned for str>::to_owned (4,149 samples, 3.28%)all..alloc::slice::<impl alloc::borrow::ToOwned for [T]>::to_owned (4,149 samples, 3.28%)all..alloc::slice::<impl [T]>::to_vec (4,149 samples, 3.28%)all..alloc::slice::<impl [T]>::to_vec_in (4,149 samples, 3.28%)all..alloc::slice::hack::to_vec (4,149 samples, 3.28%)all..rust_1brc::main (31 samples, 0.02%)__rdl_dealloc (270 samples, 0.21%)__rust_dealloc (536 samples, 0.42%)[libc.so.6] (4,262 samples, 3.37%)[li..<alloc::alloc::Global as core::alloc::Allocator>::deallocate (6,372 samples, 5.04%)<alloc..alloc::alloc::dealloc (6,372 samples, 5.04%)alloc:..cfree (5,566 samples, 4.40%)cfreecore::ptr::drop_in_place<alloc::string::String> (6,374 samples, 5.04%)core::..core::ptr::drop_in_place<alloc::vec::Vec<u8>> (6,374 samples, 5.04%)core::..core::ptr::drop_in_place<alloc::raw_vec::RawVec<u8>> (6,374 samples, 5.04%)core::..<alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop (6,374 samples, 5.04%)<alloc..core::result::Result<T,E>::expect (275 samples, 0.22%)core::num::dec2flt::<impl core::str::traits::FromStr for f32>::from_str (274 samples, 0.22%)<f32 as core::num::dec2flt::float::RawFloat>::pow10_fast_path (44 samples, 0.03%)<f32 as core::ops::arith::Div>::div (3,896 samples, 3.08%)<f3..core::num::dec2flt::number::Number::try_fast_path (4,425 samples, 3.50%)cor..core::num::dec2flt::number::Number::is_fast_path (199 samples, 0.16%)core::num::dec2flt::parse::parse_number (89 samples, 0.07%)core::num::<impl u8>::wrapping_sub (25 samples, 0.02%)<[u8] as core::num::dec2flt::common::ByteSlice>::parse_digits (2,097 samples, 1.66%)core::num::dec2flt::parse::try_parse_digits::_{{closure}} (197 samples, 0.16%)core::num::dec2flt::parse::try_parse_digits (3,597 samples, 2.84%)co..core::num::dec2flt::parse::parse_number (249 samples, 0.20%)core::num::dec2flt::parse::parse_number (7,746 samples, 6.12%)core::nu..core::num::dec2flt::parse::parse_partial_number (4,460 samples, 3.53%)cor..core::str::<impl str>::parse (15,153 samples, 11.98%)core::str::<impl s..core::num::dec2flt::<impl core::str::traits::FromStr for f32>::from_str (15,050 samples, 11.90%)core::num::dec2flt..core::num::dec2flt::dec2flt (14,214 samples, 11.24%)core::num::dec2fl..core::slice::<impl [T]>::first (264 samples, 0.21%)rust_1brc::read_line (46,204 samples, 36.52%)rust_1brc::read_linecore::str::<impl str>::split (591 samples, 0.47%)std::collections::hash::map::Entry<K,V>::and_modify (723 samples, 0.57%)rust_1brc::calculate_station_values::_{{closure}} (723 samples, 0.57%)__rdl_dealloc (296 samples, 0.23%)__rust_dealloc (362 samples, 0.29%)alloc::alloc::dealloc (3,707 samples, 2.93%)al..cfree (2,889 samples, 2.28%)c..[libc.so.6] (2,038 samples, 1.61%)std::collections::hash::map::Entry<K,V>::or_insert (3,741 samples, 2.96%)std..std::collections::hash::map::OccupiedEntry<K,V>::into_mut (3,741 samples, 2.96%)std..hashbrown::rustc_entry::RustcOccupiedEntry<K,V,A>::into_mut (3,741 samples, 2.96%)has..core::ptr::drop_in_place<hashbrown::rustc_entry::RustcOccupiedEntry<alloc::string::String,rust_1brc::StationValues>> (3,741 samples, 2.96%)cor..core::ptr::drop_in_place<core::option::Option<alloc::string::String>> (3,741 samples, 2.96%)cor..core::ptr::drop_in_place<alloc::string::String> (3,720 samples, 2.94%)co..core::ptr::drop_in_place<alloc::vec::Vec<u8>> (3,720 samples, 2.94%)co..core::ptr::drop_in_place<alloc::raw_vec::RawVec<u8>> (3,720 samples, 2.94%)co..<alloc::raw_vec::RawVec<T,A> as core::ops::drop::Drop>::drop (3,720 samples, 2.94%)<a..<alloc::alloc::Global as core::alloc::Allocator>::deallocate (3,720 samples, 2.94%)<a..rust_1brc::main (13 samples, 0.01%)core::num::<impl u64>::rotate_left (576 samples, 0.46%)<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::c_rounds (1,380 samples, 1.09%)core::num::<impl u64>::wrapping_add (280 samples, 0.22%)core::num::<impl u64>::rotate_left (2,839 samples, 2.24%)c..<core::hash::sip::Hasher<S> as core::hash::Hasher>::finish (6,341 samples, 5.01%)<core:..<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::d_rounds (3,925 samples, 3.10%)<co..core::num::<impl u64>::wrapping_add (507 samples, 0.40%)<std::hash::random::DefaultHasher as core::hash::Hasher>::finish (7,888 samples, 6.24%)<std::ha..<core::hash::sip::SipHasher13 as core::hash::Hasher>::finish (7,888 samples, 6.24%)<core::h..core::hash::BuildHasher::hash_one (1,547 samples, 1.22%)<std::hash::random::RandomState as core::hash::BuildHasher>::build_hasher (620 samples, 0.49%)core::hash::sip::SipHasher13::new_with_keys (361 samples, 0.29%)core::hash::sip::Hasher<S>::new_with_keys (361 samples, 0.29%)core::hash::sip::Hasher<S>::reset (361 samples, 0.29%)core::hash::BuildHasher::hash_one (76 samples, 0.06%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (21 samples, 0.02%)core::num::<impl u64>::rotate_left (415 samples, 0.33%)<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::c_rounds (676 samples, 0.53%)core::num::<impl u64>::wrapping_add (149 samples, 0.12%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (26 samples, 0.02%)core::hash::sip::u8to64_le (803 samples, 0.63%)core::intrinsics::copy_nonoverlapping (57 samples, 0.05%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (3,817 samples, 3.02%)<co..core::intrinsics::copy_nonoverlapping (17 samples, 0.01%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (14 samples, 0.01%)core::num::<impl u64>::rotate_left (92 samples, 0.07%)<core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::c_rounds (266 samples, 0.21%)core::num::<impl u64>::wrapping_add (90 samples, 0.07%)core::cmp::min (189 samples, 0.15%)core::cmp::Ord::min (189 samples, 0.15%)<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (189 samples, 0.15%)hashbrown::map::make_hash (16,561 samples, 13.09%)hashbrown::map::make..core::hash::BuildHasher::hash_one (16,470 samples, 13.02%)core::hash::BuildHas..core::hash::impls::<impl core::hash::Hash for &T>::hash (7,557 samples, 5.97%)core::ha..<alloc::string::String as core::hash::Hash>::hash (7,501 samples, 5.93%)<alloc::..core::hash::impls::<impl core::hash::Hash for str>::hash (7,501 samples, 5.93%)core::ha..<std::hash::random::DefaultHasher as core::hash::Hasher>::write_str (7,501 samples, 5.93%)<std::ha..<core::hash::sip::SipHasher13 as core::hash::Hasher>::write_str (7,501 samples, 5.93%)<core::h..<core::hash::sip::Hasher<S> as core::hash::Hasher>::write_str (7,501 samples, 5.93%)<core::h..core::hash::Hasher::write_u8 (3,619 samples, 2.86%)co..<core::hash::sip::Hasher<S> as core::hash::Hasher>::write (3,375 samples, 2.67%)<c..core::hash::sip::u8to64_le (927 samples, 0.73%)core::num::nonzero::NonZero<u16>::new (32 samples, 0.03%)<hashbrown::raw::bitmask::BitMaskIter as core::iter::traits::iterator::Iterator>::next (35 samples, 0.03%)hashbrown::raw::bitmask::BitMask::lowest_set_bit (35 samples, 0.03%)hashbrown::raw::RawTable<T,A>::bucket (547 samples, 0.43%)hashbrown::raw::Bucket<T>::from_base_index (547 samples, 0.43%)core::ptr::mut_ptr::<impl *mut T>::sub (547 samples, 0.43%)core::ptr::mut_ptr::<impl *mut T>::offset (277 samples, 0.22%)hashbrown::raw::RawTable<T,A>::find::_{{closure}} (9,752 samples, 7.71%)hashbrown::..hashbrown::rustc_entry::_<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry::_{{closure}} (9,204 samples, 7.28%)hashbrown:..<alloc::string::String as core::cmp::PartialEq>::eq (9,204 samples, 7.28%)<alloc::st..alloc::vec::partial_eq::<impl core::cmp::PartialEq<alloc::vec::Vec<U,A2>> for alloc::vec::Vec<T,A1>>::eq (9,204 samples, 7.28%)alloc::vec..core::slice::cmp::<impl core::cmp::PartialEq<[B]> for [A]>::eq (9,204 samples, 7.28%)core::slic..<[A] as core::slice::cmp::SlicePartialEq<B>>::equal (9,204 samples, 7.28%)<[A] as co..[libc.so.6] (6,225 samples, 4.92%)[libc...hashbrown::raw::h2 (1,988 samples, 1.57%)hashbrown::raw::sse2::Group::load (87 samples, 0.07%)core::core_arch::x86::sse2::_mm_loadu_si128 (87 samples, 0.07%)hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (84 samples, 0.07%)hashbrown::raw::sse2::Group::match_byte (2,523 samples, 1.99%)h..core::core_arch::x86::sse2::_mm_movemask_epi8 (2,523 samples, 1.99%)c..hashbrown::raw::sse2::Group::match_empty (323 samples, 0.26%)hashbrown::raw::sse2::Group::match_byte (323 samples, 0.26%)core::core_arch::x86::sse2::_mm_movemask_epi8 (323 samples, 0.26%)hashbrown::raw::RawTableInner::find_inner (16,965 samples, 13.41%)hashbrown::raw::RawT..hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (390 samples, 0.31%)hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (35,084 samples, 27.73%)hashbrown::rustc_entry::<impl hashbrown::map:..hashbrown::raw::RawTable<T,A>::find (16,989 samples, 13.43%)hashbrown::raw::RawT..hashbrown::rustc_entry::<impl hashbrown::map::HashMap<K,V,S,A>>::rustc_entry (22 samples, 0.02%)rust_1brc::main (533 samples, 0.42%)rust_1brc::calculate_station_values (124,959 samples, 98.78%)rust_1brc::calculate_station_valuesstd::collections::hash::map::HashMap<K,V,S>::entry (36,056 samples, 28.50%)std::collections::hash::map::HashMap<K,V,S>::e..std::collections::hash::map::map_entry (201 samples, 0.16%)rust_1brc::main (212 samples, 0.17%)core::str::converts::from_utf8 (1,306 samples, 1.03%)core::str::validations::run_utf8_validation (1,305 samples, 1.03%)core::str::validations::utf8_char_width (74 samples, 0.06%)all (126,508 samples, 100%)rust-1brc (126,508 samples, 100.00%)rust-1brc_start (126,501 samples, 99.99%)_start__libc_start_main (126,501 samples, 99.99%)__libc_start_main[libc.so.6] (126,501 samples, 99.99%)[libc.so.6]main (126,501 samples, 99.99%)mainstd::rt::lang_start_internal (126,501 samples, 99.99%)std::rt::lang_start_internalstd::rt::lang_start::_{{closure}} (126,501 samples, 99.99%)std::rt::lang_start::_{{closure}}std::sys_common::backtrace::__rust_begin_short_backtrace (126,501 samples, 99.99%)std::sys_common::backtrace::__rust_begin_short_backtracecore::ops::function::FnOnce::call_once (126,501 samples, 99.99%)core::ops::function::FnOnce::call_oncerust_1brc::main (126,501 samples, 99.99%)rust_1brc::mainstd::fs::read_to_string (1,329 samples, 1.05%)std::fs::read_to_string::inner (1,329 samples, 1.05%)std::io::default_read_to_end (23 samples, 0.02%) \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 90cc7a6..fa089c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,10 +23,10 @@ struct StationValues { } fn read_line(data: String) -> (String, f32) { - let parts: Vec<&str> = data.split(';').collect(); - let station_name = parts[0].to_string(); - let value = parts[1].parse::().expect("Failed to parse value"); - (station_name, value) + let mut parts = data.split(';'); + let station_name = parts.next().expect("Failed to parse station name"); + let value = parts.next().expect("Failed to parse value string").parse::().expect("Failed to parse value"); + (station_name.to_owned(), value) } // Calculate the station values