I managed to get some more nanoseconds for the manual conversion by just simply doing that :) int length = yearAsSpan.Length; for (int i = 0; i < length; i++) { temp = temp * 10 + (yearAsSpan[i] - '0'); }
@RetroRick19903 жыл бұрын
That's great, now I have more confidence in showing off my work without having all the boring discussions about what is fast and what is not... There is always that guy who thing his code is very small and this is the way to go...
@harag93 жыл бұрын
Agree, and when I saw the last change Nick did, it blew me away as it's the longest code there, and even a loop.
@subhamagarwal17164 жыл бұрын
Stunned after seeing the results.....Its amazing.....Looking for more videos like this
@athar33533 жыл бұрын
I feel so bad that I just recently came to know about your videos. Please keep sharing your knowledge regularly. Means a lot to me.
@utubekade3 жыл бұрын
One of the best programming channels on KZbin. Many useful topics for all levels of programmers. Kudos.
@millch2k83 жыл бұрын
Great video!... I was surprised that the manual conversion (ie. the final one) was so much quicker still. I'd have naively assumed that int.Parse would have been pretty well optimized under the hood. Definitely a learning experience to see that.
@zondaken2 жыл бұрын
Parsing is a complex process that needs to cover a lot of edge cases. The last benchmark uses a computation that ASSUMES that the date is in the right format. If it's not, you'll likely get problems. This is what int.Parse tries to avoid/counter.
@RobEdwards3692 жыл бұрын
Thanks so much for all you do. I just did my first ever benchmark. I was able to reduce my method from 87000ns/16272B to 4ns/24B. What is the best though isn't this individual case, it's being able to try various techniques and observe not just how fast/mem hungry they are but how they scale. It leads to increased understanding of performance generally so in the future I hope to know when I should say use linq or as in this case write an extra 4 lines of code and do it myself.
@JedidiJedidi4 жыл бұрын
Continue the great work. I just binge-watched all your videos even the stuff that I already know.
@harag93 жыл бұрын
Fairly new to your channel and was curious when you used [Benchmark] so watched this... WOW impressed with the last change you did, 4 times the length of code, and yet it ran so quick. Thanks for sharing!
@Myself00942 жыл бұрын
Great stuff! Wrote my first benchmark today. Was very interesting to see huge difference in performance between lambda assignments and direct assignments in my own case. Though it had very small impact on a calling context execution.
@noctavel4 жыл бұрын
Can't believe int.parse is slower than that last funcion :0
@geoffxander79704 жыл бұрын
He went old school and banged out atoi(). I like it. But this is great info, I'll probably use this in a few months.
@millch2k83 жыл бұрын
That definitely threw me as well.
@thiagomatu4 жыл бұрын
wow, that's great, would be nice if you can continue with this video!
@billias284 жыл бұрын
Excellent presentation of the topic. Thank you once again for your great work !
@jmangan3 жыл бұрын
Great video Nick, everything I needed to get me started on this topic. Keep up the good work!
@PeterOeC2 жыл бұрын
This video series is 🔥 bro! Thank you for making the videos! Subscribed!
@minhan44449 ай бұрын
Thank you for video about benchmark
@dheeraj00762 жыл бұрын
HI Nick, I love watching your tutorials. You are a great source of knowledge and I want to thank you for that. Just a suggestion: Would you mind keeping your fonts little bigger to ease our eyes? Thanks :)
@Emis3333 жыл бұрын
Amazing work, simple and straight to the point.
@moab51023 жыл бұрын
Excellent presentation as always. watched this video few times now, I'd like to see more bench marking and optimizations videos, Thank you once again for your great work.
@MiikaKontio3 жыл бұрын
Very interesting topic. Thanks for introducing it to me
@Azukayoshi4 жыл бұрын
Amazing Job man! Thanks for the dazzling work!
@two-bitcoding80183 жыл бұрын
Thank you for this video. Really helped me with my project!
@Victoare3 жыл бұрын
Great video Nick. Binging through your uploads :) Also .. why find the hyphen at all? IndexOfHypen should always be 4. At this scale all method calls should be avoided. :D
@harag93 жыл бұрын
I was wondering that, why not just get the 4 characters as you know the format and that it's the year... Now I need to copy his code and do the tests myself :)
@Fasiibcs4 жыл бұрын
Nice work, please make an advance video on this topic.
@mabakoo4 жыл бұрын
Excellent explanation of benchmarking. Can you help in benchmarking codes that relate to message transmission. Something like performance between signalr and rabbitmq to transmit messages
@jaysennaidoo2 ай бұрын
Many years later, it seems that .NET8 optimizations for int.Parse() means that it runs faster than the manual conversion with spans
@ismailm1234 жыл бұрын
Really enjoyed this useful video, very well explained.
@davidopdebeeck89533 жыл бұрын
Fantastic teach dude, thanks so much!!!
@ahmeddan77344 жыл бұрын
thanks for sharing. that's is such a great tutorial and well done
@mihaimyh3 жыл бұрын
Great video, I would love for a more in-depth one.
@ARS-fi5dp2 жыл бұрын
Thank you a lot ❤
@R.B.2 жыл бұрын
I'm not completely sure why, but I was actually getting better performance passing in the string as a parameter, just like the other functions and then converting to a span within the function: ``` public int GetYearFromSpan(string dateTimeAsString) { var span = dateTimeAsString.AsSpan(); var indexOfHyphen = span.IndexOf('-'); return int.Parse(span[..indexOfHyphen]); } ``` My best performing method was this (optimizing out that the index will be 4, but the difference is nominal): ``` public int GetYearFromSpanWithManualConversionUsingForeach(string dateTimeAsString) { var yearAsSpan = dateTimeAsString.AsSpan()[..4]; var temp = 0; foreach (var c in yearAsSpan) { temp = temp * 10 + (c - '0'); } return temp; } ``` The first here, creating the Span inside the method is 0.031 (32.25 times faster) of the base, and the tightest optimization with the manual conversion is 0.007 (142.85 times faster). I was a little surprised with this outcome... (while putting this together and subsequent runs it seems that passing in the ReadOnlySpan is sometimes slightly faster, but both are within the Error). Personally it makes more sense to me to keep the signature the same if there is such an insignificant difference. I ran this against .NET 6.0.0.
@arty_3794 Жыл бұрын
Thank you for video
@elmenolnecio2 жыл бұрын
Pretty Good man!!
@manojtayde2 жыл бұрын
Can we use BenchmarkDotNet with the NUnit framework and compare the result with the baseline result? We have CodeAnalyzer rules which are running very slow so want to check the performance. Can I achieve the same through BenchmarkDotNet ?
@tullochgorum6323 Жыл бұрын
Wondering why you were getting the index of the hyphen at runtime, when you know the length of the date in advance (4 chars) so it could be hard-coded. Am I missing something?
@richardc2154 жыл бұрын
Good stuff. Please make an advance video on this topic.
@deanbullen90212 жыл бұрын
Thanks for this, great video. So is this something you should always create a dedicated app for, or is it ok to put benchmarking inside your real business app (eg a web app)?
@anastasiiamelnyk60722 жыл бұрын
Thank you for great video! How do you think does it make sense to run Benchmark for retrieving data from database? I want to figure out what is better, run stored procedure or complicated select query.
@serhiihorun62984 жыл бұрын
Thank you
@cartman_soc2 жыл бұрын
nice video, can you use it with xUnit ?
@zbaktube Жыл бұрын
The quickest solution here is to simple return 2019. Though this solution might not be accurate in each cases🙂
@nykytakudrya77414 жыл бұрын
thank you very much!!!!!
@imoto8709 Жыл бұрын
great
@sabitkondakc91473 жыл бұрын
thanks for this amazing video, benchmark is used by many depelopers lately it provides flexibility to analyze performance exc. but I've a problem; it takes a lot of time for large size arrays I think it's about my machine, intel i5 , 4 logical 2 physical core. does it take long to analyze with an array of [8000,8000] by your PC , which looks like a monster, 8 physical cores, damn boi ?
@cuongme6262 жыл бұрын
Great video! Can someone explain the manual conversion logic? (ie. * 10 and + ‘0’). Thanks!
@hinekde2 жыл бұрын
Brackets first: Every character has a numeric value, when you look in a ASCII table for example, you see, that the character '0' is at decimal 48, '1' is 49, etc. so if you subtract '0' from a char that is between '0' and '9', you get numerical value of the displayed number. Example: ('3' - '0') = (51 - 48) = 3
@hinekde2 жыл бұрын
Then the temp * 10: the loop starts at the most left character, that is the highest position of the number. So if the span is '2019', in the first iteration it reads the 2, so temp = 0 * 10 + 2 = 2 next loop it reads the 0 and adds it to the previous value times 10, so temp = 2 * 10 + 0 = 20 + 0 = 20 next loop it reads the 1 and adds it to the previous value times 10, so temp = 20 * 10 + 1 = 200 + 1 = 201 last loop it reads the 9 and adds it to the previous value times 10, so temp = 201 * 10 + 9 = 2010 + 9 = 2019
@adamowski103 жыл бұрын
Hi, great video:) How can I mesure cpu usage with BenchmarkDotNet?
@zoltantorok11896 ай бұрын
You make the distinction between this (benchmarking) and profiling. The video is 4 years old and you have nothing on profiling. Could you make a video on profiling?
@md.mizanurrahmanmilon37454 жыл бұрын
awesome
@koorshashirazi20374 жыл бұрын
Awesome 👌👌👌
@andinofaturahman36493 жыл бұрын
Is the result will same in xamarin ? or is benchmark valid if i run it on xamarin app ? bethink native for mobile apps is java for android.
@dotnetdevni2 жыл бұрын
Can you run it inside unit tests at all
@nickchapsas2 жыл бұрын
You wouldn’t run it inside unit tests but you could have it as part of your CI pipeline and run it there