No video

Arrays vs Lists

  Рет қаралды 6,149

Coding Tutorials

Coding Tutorials

Күн бұрын

What do Santa Claus and the .NET runtime have in common? When they make a list, they check it twice.
Source code available at: github.com/Jas...
Topics include:
- C# collection performance
- Comparing generic lists and arrays in .NET
- Underlying collection structures
- Collection benchmarking

Пікірлер: 24
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
What's your worst performance mistake? Let me know in the comments. Source code available at: github.com/JasperKent/List-Versus-Array Remember to subscribe at kzbin.info/door/qWQzlUDdllnLmtgfSgYTCA And if you liked the video, click the 👍.
@Mati22011995
@Mati22011995 2 жыл бұрын
Your channel is goldmine! Huge respect
@kurumi690
@kurumi690 Жыл бұрын
I found your channel recently, but I surprised of quality of your videos. Thx for your tutorials 😊
@imikhan83
@imikhan83 2 жыл бұрын
Thank you for the explanation. Always learn things from you ❤
@vladmaiorov1072
@vladmaiorov1072 Ай бұрын
Great job!
@davidwhite2011
@davidwhite2011 2 жыл бұрын
Another gem.
@williamgomes3730
@williamgomes3730 2 жыл бұрын
Your channel it's awsome.
@tayablackrose29
@tayablackrose29 2 жыл бұрын
Something like a open/closed state of a List would be useful to have the best of both worlds. In open state it would act as a regular List and in closed state would be have a fixed size like an Array. To have .closed() method which would change its internal bool state and free up unassigned memory.
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
Yeah, but I think you'd still have to do the copy.
@vendettasnares
@vendettasnares Жыл бұрын
11:11 wow
@RiversJ
@RiversJ Жыл бұрын
In hot paths the difference can be between meeting or not meeting requirements.
@MrXzxzxc
@MrXzxzxc 2 жыл бұрын
The trade-off at the end of the video can be harmful in terms of GC. If you call this code many times, GC time can be longer than iteration over the list with the double check. Especially if you have a web app scenario, having 100 slightly slower requests can be better than having 99 faster requests and one really slow one (when GC happens), for example, if you have a timeout at the client side.
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
Absolutely. IN the end, with any performance question, you've got to measure what is actually effective.
@0i0l0o
@0i0l0o Жыл бұрын
Beatiful.
@Maxim_Grekov
@Maxim_Grekov 2 жыл бұрын
I got such message when running program. Please, give me a tip what's going on? // Validating benchmarks: Assembly ListVersusArray which defines benchmarks is non-optimized Benchmark was built without enabled (most probably a DEBUG configuration). Please, build it in RELEASE.
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
You can only benchmark a release build. See kzbin.info/www/bejne/gWPPo2aMe5WqeJo
@Maxim_Grekov
@Maxim_Grekov 2 жыл бұрын
Much thanks!
@muireachgriogalach483
@muireachgriogalach483 2 жыл бұрын
arrays vs dicts(hash tables), who wins at performance and speed ?
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
I'll leave it to you to do the benchmarking, but my bet would be on arrays.
@Maxim_Grekov
@Maxim_Grekov 2 жыл бұрын
Tell me please Jasper, is this example specific only to VS2022?
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
The basic principles apply way back to the early days of .NET Framework. The top-level statements in program.cs only work in C# 9 or later. For older versions, just put all that code in Program.Main().
@dd-rm6ju
@dd-rm6ju 2 жыл бұрын
cool, keep it up ._.
@petrusion2827
@petrusion2827 2 жыл бұрын
I recommend *against* doing this, but if anyone is curious how you would read array elements without bounds checks, like this: int[] arr = new int[10]; // get reference to element at [0] without bounds checks ref int first = ref MemoryMarshal.GetArrayDataReference(arr); // add 4 elements to the reference, making a new reference that points to element at [4] // then dereference it, now you read the fifth element without bounds checks int fifth = Unsafe.Add(ref first, 4); That being said though, if you write a *for* loop for the array, the bounds checks should be compiled away anyway.
@CodingTutorialsAreGo
@CodingTutorialsAreGo 2 жыл бұрын
As you say - not recommended.
Indexers, Properties and Encapsulation
15:47
Coding Tutorials
Рет қаралды 1,5 М.
C# Covariance
17:27
Coding Tutorials
Рет қаралды 7 М.
天使救了路飞!#天使#小丑#路飞#家庭
00:35
家庭搞笑日记
Рет қаралды 92 МЛН
طردت النملة من المنزل😡 ماذا فعل؟🥲
00:25
Cool Tool SHORTS Arabic
Рет қаралды 17 МЛН
这三姐弟太会藏了!#小丑#天使#路飞#家庭#搞笑
00:24
家庭搞笑日记
Рет қаралды 32 МЛН
Why Linked Lists vs Arrays isn’t a real choice
9:15
SimonDev
Рет қаралды 309 М.
C# Array vs Dictionary vs List a Beginners Guide in .NET
20:48
thedevlife
Рет қаралды 10 М.
When to use - IEnumerable vs IList vs ICollection?
12:05
DotNetMastery
Рет қаралды 47 М.
C# Arrays, Lists, and Dictionaries (Quick dotnet tutorial)
19:51
Dev Leader
Рет қаралды 2,3 М.
C# 12 Collection Expressions and the Spread Operator
25:27
Coding Tutorials
Рет қаралды 1,9 М.
Stackalloc and Spans
30:17
Coding Tutorials
Рет қаралды 10 М.
What Are You Awaiting For?
21:39
Coding Tutorials
Рет қаралды 4,1 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 151 М.
7.4 Differences between Arrays & Lists - Learning C#
9:29
ParametricCamp
Рет қаралды 6 М.
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 252 М.