Skip to content

Instantly share code, notes, and snippets.

Using rustc -Copt-level=3 --test extend.rs && ./extend --bench
name before-extend.log ns/iter after-extend.log ns/iter diff ns/iter diff %
bench_chain_collect 53,317 18,039 -35,278 -66.17%
bench_chain_extend_ref 18,105 17,945 -160 -0.88%
bench_chain_extend_value 22,425 18,016 -4,409 -19.66%
bench_map_fast 5,970 6,021 51 0.85%
bench_map_regular 14,242 6,088 -8,154 -57.25%
bench_range_map_collect 12,727 1,954 -10,773 -84.65%
bench_rev_1 14,132 2,574 -11,558 -81.79%
@bluss
bluss / extend.ll
Last active October 20, 2016 15:36
` rustc -Copt-level=3 --test extend.rs --emit=llvm-ir` using `rustc 1.14.0-nightly (16eeeac78 2016-10-18)` for just bench_chain_extend_ref from https://gist.github.com/bluss/baa98105d141cff3949dda1c1f2d8cce
; ModuleID = 'extend.cgu-0.rs'
source_filename = "extend.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%str_slice = type { i8*, i64 }
%"12.test::Bencher" = type { i64, %"1.std::time::Duration", i64 }
%"1.std::time::Duration" = type { i64, i32 }
%"3.std::vec::Vec<u32>" = type { %"5.alloc::raw_vec::RawVec<u32>", i64 }
%"5.alloc::raw_vec::RawVec<u32>" = type { %"2.std::ptr::Unique<u32>", i64 }
; ModuleID = 'chain_more_codegen.cgu-0.rs'
source_filename = "chain_more_codegen.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
define i64 @range_chain_default_fold(i64, i64, i64 (i64, i64)* nocapture) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
; ModuleID = 'chain_more_codegen.cgu-0.rs'
source_filename = "chain_more_codegen.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
define i64 @range_chain_default_fold(i64, i64, i64 (i64, i64)* nocapture) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
; ModuleID = 'chain_two_calls.cgu-0.rs'
source_filename = "chain_two_calls.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
define i64 @range_chain_default_fold(i64, i64, i64 (i64, i64)* nocapture) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
; ModuleID = 'chain_two_calls.cgu-0.rs'
source_filename = "chain_two_calls.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
define i64 @range_chain_default_fold(i64, i64, i64 (i64, i64)* nocapture) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
; ModuleID = 'chain_two_calls_really.cgu-0.rs'
source_filename = "chain_two_calls_really.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
define i64 @range_chain_default_fold(i64, i64, i64 (i64, i64)* nocapture) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
; ModuleID = 'chain_bool.cgu-0.rs'
source_filename = "chain_bool.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
define i64 @range_chain_default_fold(i64, i64, i64 (i64, i64)* nocapture) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
; ModuleID = 'chain_bool_split.cgu-0.rs'
source_filename = "chain_bool_split.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"2.std::ops::Range<usize>" = type { i64, i64 }
%"8.unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"8.unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"8.unwind::libunwind::_Unwind_Context" = type {}
; Function Attrs: uwtable
@bluss
bluss / 0-benchmark-result
Last active October 27, 2016 17:29
(Note: I also tested instead of chaining on single elements, chaining the slice half and half, and qualitatively it has the same result)
Improvements with impl TrustedLen on Chain, and using TrustedLen in Vec::extend
name extend-before-1.log ns/iter extend-after-1.log ns/iter diff ns/iter diff %
bench_chain_chain_collect 62,249 32,370 -29,879 -48.00%
bench_chain_collect 26,828 25,386 -1,442 -5.37%
bench_nest_chain_chain_collect 44,562 41,087 -3,475 -7.80%
/Additional/ improvements using `.fold()` too in Vec::extend
name extend-after-1.log ns/iter extend-after-fold-2.log ns/iter diff ns/iter diff %