diff --git a/benchmarks/src/iota.cpp b/benchmarks/src/iota.cpp index 9d96d12d773..5860b1b605e 100644 --- a/benchmarks/src/iota.cpp +++ b/benchmarks/src/iota.cpp @@ -7,14 +7,24 @@ #include #include -template +enum class Alg { + Std, + Rng, +}; + +template void bm(benchmark::State& state) { const auto size = static_cast(state.range(0)); std::vector a(size); for (auto _ : state) { - std::iota(a.begin(), a.end(), T{22}); + if constexpr (Algorithm == Alg::Std) { + std::iota(a.begin(), a.end(), T{22}); + } else if constexpr (Algorithm == Alg::Rng) { + std::ranges::iota(a, T{22}); + } + benchmark::DoNotOptimize(a); } } @@ -23,7 +33,10 @@ void common_args(auto bm) { bm->Arg(7)->Arg(18)->Arg(43)->Arg(131)->Arg(315)->Arg(1212); } -BENCHMARK(bm)->Apply(common_args); -BENCHMARK(bm)->Apply(common_args); +BENCHMARK(bm)->Apply(common_args); +BENCHMARK(bm)->Apply(common_args); + +BENCHMARK(bm)->Apply(common_args); +BENCHMARK(bm)->Apply(common_args); BENCHMARK_MAIN(); diff --git a/stl/inc/numeric b/stl/inc/numeric index a0186094e52..9f4af6eb911 100644 --- a/stl/inc/numeric +++ b/stl/inc/numeric @@ -567,6 +567,24 @@ namespace ranges { _STL_INTERNAL_STATIC_ASSERT(weakly_incrementable<_Ty>); _STL_INTERNAL_STATIC_ASSERT(indirectly_writable<_It, const _Ty&>); + if constexpr (_Iterator_is_contiguous<_It> && sized_sentinel_for<_Se, _It> && is_integral_v<_Ty> + && sizeof(_Ty) >= 4) { + // TRANSITION, DevCom-10593477: help the compiler vectorize + const auto _Ptr = _To_address(_First); + const auto _Size = static_cast(_Last - _First); + + if (_STD _In_range<_Ty>(_Size)) { + const auto _Size_typed = static_cast<_Ty>(_Size); + for (_Ty _Ix = 0; _Ix != _Size_typed; ++_Ix) { + const _Ty _Const_val = _Val + _Ix; + _Ptr[_Ix] = _Const_val; + } + + _Val += _Size_typed; + return _First + _Size; + } + } + const _Ty& _Const_val = _Val; for (; _First != _Last; ++_First, (void) ++_Val) { *_First = _Const_val;