4 ms·
Does C# have the plumbing for this built in? It's been 7 years since using it so I might not be remembering correctly.
by davidmurdoch 2y ago
Does C# have the plumbing for this built in? It's been 7 years since using it so I might not be remembering correctly.
- neonsunset 2y agoIEnumerable<T>.Max and .Min are the same as they were just significantly faster through the use of SIMD: https://github.com/dotnet/runtime/blob/ebbebaca1184940f06df609d5a40096f628200ce/src/libraries/System.Linq/src/System/Linq/MaxMin.cs#L22 https://github.com/dotnet/runtime/blob/ebbebaca1184940f06df6... You could implement a similar (and simpler) fast path for types with contiguous memory by performing min and max per iteration instead.
- davidmurdoch 2y agoI was thinking LINQ was optimized to do a single enumeration for cases such as this. Can LINQ be easily, naturally, and idiomatically used with `IEnumerable<T>.Max` and `.Min` to avoid looping twice, or is it more of a more rigorous and intentional optimization the engineer would have to seek out?