Intro to Benchmark.net - How To Benchmark C# Code

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how efficient is your code is the change you just made going to improve your application or not and how do you know how important was that change these questions cannot be answered without benchmarking in this lesson we're going to look at how to use benchmark.net to evaluate code in order to identify how efficient it is and how efficient it is compared to a changed version of that same code now this is the first video you watched of mine my name is tim cory it's my goal to make learning c-sharp easier i provide videos twice a week here on youtube to help you grow as a developer on mondays we talk about in-depth code stuff and on thursdays we get into a podcast series called dev questions where i answer your questions around the programming realm not necessarily specifically on specific code bits all right so check out what i have to offer i also have training on imtimcorey.com those are full courses that are at a very high level built to provide you with real world training that gets you ready to go right away now in this video as with most of my videos i'm going to create some source code if you like a copy of source code go use a link in the description to get that code all right let's go over to visual studio i'm using 2019 the latest or almost latest version i am due for an upgrade to 16.10 clicking on 16.9 but the changes are minor enough that shouldn't cause any problems and i didn't want to upgrade right before i recorded a video so let's go down here to create a new project we're going to say a console application we don't need to have anything complicated here i want to get as much stuff out of the way in fact the console application is going to make sure that we have very little running besides our test code think of benchmarking kind of like unit testing in the fact you want to strip everything else away you don't want to have a lot of complex interactions if you don't have to if that's not what you're testing now we're not going to get into more complicated testing like maybe testing an interaction includes a database or an api something like that that'd be a little more complicated but still something you'd probably do in a console you'll probably be testing against a dll or something else like that and so that's where you're going to bring that into your console application all right so let's call this our benchmark let's call it benchmarker and then we'll call it benchmarker app and we'll put in samples and hit next we're going to use dot net 5 which is the current version as of the recording this video and this will allow us to run c-sharp for linux mac os and windows so this is the console app hopefully you're familiar with the console app if not maybe it's a little too advanced for you you might want to go back and watch other videos introduced in the console and how it works now the first step here where i get rid of the console.writeline in here and clean us up a little bit and then we're going to right click on dependencies and we're going to manage nuget packages and in here we're going to browse we're going to search for benchmark dot net spell it all out benchmark.net and there we go we have benchmark.net it's got eight point four four million downloads as of the recording this video the least steel version is zero point 0.13.1 this is a newer product they're still working on but at the same time it is working it is um it does work as is and it's not something where it's a pre-production version you can't use you can definitely use this for benchmarking your your stuff let's go ahead and hit install just the main version hit okay and i accept and now in here we can do is i'm actually whoops i said control s there and it popped up a dialog box all right i want to create a new class now normally i create a new class by right clicking on the project and saying add new class i'm going to create right here so i can see both at the same time where i create a very very simple benchmark for you to see and then i'll move the class over so let's create a public class let's just call it demo let me use the shift enter to get my curly braces that's a newer feature in net also notice that um i'll have some what did not show up right now you don't have any let's bring that back a minute like so uh if you see this value pop up that's another tools options uh setting that's not something it's a plug-in or something else i get asked that question a lot that's a newer version of visual studio option i believe it came in 16.9 and you can enable it so i do have a video talking about that if you need a link for that let me know down in the comments and i'll link to it okay so inside of the demo class the actually above the demo class we're going to put in square brackets we're going to say memory diagnoser and do control dot on that to add the using for benchmark.net.attributes so that adds that using statement up here and what this will do is it's going to add a diagnoser so built in is already a diagnose we're going to add a second one which is the memory diagnoser i'll show you the difference with this on and off but what this does is it allows us to see how much memory is going to use in fact let's let's turn it off for right now now you've got that using statement in place i'll turn it off at first and then we'll add it so you can see that the additive difference now down here we're going to create a method public string we're going to say get get full string and we'll say normally and the reason i say normally is because we're going to modify this in a little bit and so in this method we're going to say is string outputs and then um let's just say string output equals empty string and we're going to say for a for loop we'll say i is less than 100 and then we're going to say output plus equals i so this will do is it will say the output when it finally comes out will be 0 one two three four five six don't count up but on one one lumped together string all right so is this an effect efficient and cool method no it's not but it's gonna give us a good starting point to show off the benchmark class so we're going to return output that returns the the full strength right so this is the the method we want to benchmark to do that we simply say benchmark done we have now marked this as ready to be benchmarked so how do we actually benchmark or run this benchmark well we scroll the top here in our static void main we can say var results equals benchmark runner ctrl dot there to add that using for using benchmark.net.running and we'll say dot run demo this will run this class and look for these benchmark methods this is kind of like unit testing where we say hey this is a test go ahead and run that well this is a benchmark method go ahead and run that now you're almost ready to run this but there is a couple more changes first of all right up here we have debug mode let's let's me stretch this out i can't all right uh because the way that my my fonts are enlarged you can only see debug but this is debug mode by default we're going to change that to release mode now if you're not familiar with the difference between debug mode and release mode we do we run debug mode when we're using visual studio when we are doing development because it does some less efficient things in order to give us more things to look at more debuggability for example normally when you're done using a variable it goes away but in debug mode it's going to keep it for longer it's not going to let the garbage collector run as often and the reason why is because that way you can go back and inspect things later so with the the debug mode on it's not as efficient and it's not something you'd use for production in release mode it takes away all that debugging stuff it only does what is most efficient it's not as easy to debug that but it is much more efficient which is what you want for production so that's why when you have a build server your build server should always be running the release mode or building and release mode whereas when you're in visual studio you should always be or almost always be running in debug mode so in our case we use release mode because we're trying to identify the efficiency of this method the way we identify the efficiency is if we run it the most efficient way so therefore release mode okay and one last thing if we hit this play button here that's going to run and attach the debugger even in release mode it's going to attach the debugger which means it's going to have hooks into the application to listen to the various events and try and put break you know try to listen for break points and so on but we don't want that because that's going to add memory overhead and skew the tests so we want to go a debug menu and run without debugging or control f5 so that's where i do run without debugging this will compile the project and it will start this process of running the the um the benchmark now what is a benchmark i'm going to talk this while it's running because it's going to run for a little while a benchmark is going to identify how efficient the app the method is based upon running a number of times but when you run a a system the first time what happens is there's some startup cost and so what this does it's gonna run a few times which is already done it's gonna run a few times here as warm-ups so it does some warm-up stuff and throws those results away and then does the actual testing so in this case we now have a completed benchmark now this benchmark is almost useless but i wanted to see i want you to see it at the very beginning to see what a a trimmed down just benchmarking one method thing would look like so first of all it does say okay based upon this operating system this version the operating system which is the october 2020 update based upon this process or these cpus based upon this version of net sdk based upon the job running on 5.0.9 of net so it's it's making sure that you know all of the the things that went into this benchmark because these numbers will not be the same as the numbers on your machine and that's okay what these numbers are not telling you is how fast this will run these numbers tell you how fast they'll run on your machine which isn't terribly useful if you're talking about figure out for a production environment but that's not what benchmarking is all about so we're gonna get into how is benchmarking useful and really when you're running one thing like this it's not terribly useful okay so we're gonna see how to do comparisons that's really where the the benchmarking value comes from but i want to see us up front how to do just the one all right so this is the method get full string normally the mean or average was 3.014 usd which us is one microsecond or 0.0001 seconds which yes that's very very very fast and if that went from three to six no one would notice but um this is how long our method is taking three microseconds on average there is the error rate and there is the standard deviation which they talk about the confidence and the deviation of all measurements if you are are a math person this might be even more interesting to you so by default what happens when we run this benchmark on one method the default benchmark is that we're going to get how long does it take on average to run that method three microseconds now let's go back and look i commented out this memory diagnoser let's uncomment that this memory diagnosis is going to add even more to this benchmark let's run it again oops can't hit the run button if you do what's going to happen at least on mine it's going to say hey you're debugging and release mode i want to stop doing that that's what i've got the just my code turned on and some other things it might not pop up for you but make sure that you instead start without debugging so what this is going to do is it's going to run those same tests the same way it's going to do the warm up and all the rest but now it's not only going to capture how long an average it takes to run that method but also the the memory implications for using this this method and this can be very important because sometimes how long it takes isn't the only piece of data so for instance it took 3.049 microseconds to run this method pretty close to the last time but now we have gen 0 gen 1 and allocated so what do these things mean well it kind of explains it down here gen 0 is gc generated 0 collects per thousand operations which if you are not a really understanding of what gc is then that can be very very complicated and confusing i get that gc stands for garbage collection and what dot net does behind the scenes is it says okay instead of just cleaning up the memory every time there is a a thing that's no longer used i'll wait until it's necessary so think of memory uh let's look at mary as this long line right here okay so this is the memory that's filled this white section now imagine if the the letters gc that represented a variable that's no longer needed well that goes away and those two spaces are available but they're not really because they're kind of in the middle and they're only a certain length and and so on so what happens with garbage collection is it comes along and says oh hey you know what we can get rid of that memory usage it removes it from memory and then it compresses down this line so that the line now has two less spots at the end therefore we can have a new thing take up just two spaces or even more because we have the space for it but that's expensive it's not something you want to do just on a whim otherwise it's going to take more memory to clean the memory than the memory you're saving which is counterintuitive this is why the garbage collection system is a really impressive piece of engineering that almost certainly you should not mess with don't just do garbage collection calls don't force it to run let it do its thing but gen zero what this is is that garbage collection system says okay i'm gonna run because i need to and i'm gonna figure out all the things that are not need anymore i'm going to get rid of those and compress the rest but then i'm going to mark everything that i have not gotten rid of as gen 1 which means it survived one purge because the theory is that if a variable is not short lived means it's going to live for a little bit longer then it's probably live for even longer meaning the if a variable lives for a little bit it'll probably live for longer than that so therefore gets moved at gen 1 and then if needed the garbage collector will come back to gen 1 but it may run gen 0 over and over and over again only on the new allocated things because it's moved everything else to gen 1. now if it does a gen 1 again or gen 0 again it's going to move everything is left back to gen 1. however if it says you know what i needed more i'm going to go to gen 1 items as well it's going to do the same exact thing with the gen 1 items we're going to look at them and it's going to say okay these things i can get rid of i'll compress the rest i'll mark everything else it's gen two and it moves everything else up one level and does it all over again okay that's a very simplified very um simple version of what the very complex garbage collection system does so we'll probably go into it in much more depth in another video let me know if you want to see that video and how much it interests you down the comments so what this is saying is how many times the garbage collector run for gen zero per 1000 operations not per one operation per thousand operations and the same is true for gen 1. so how many times the garbage collector collected per 1000 operations so up here we see that we've run 2.8343 times per 1000 operations so the gen zero garbage collector has run 2.8 times every thousand calls the gen 1 garbage collector has run .0038 times per 1000 calls obviously we want this to run a lot less because it's the more expensive do more uh call than the gen zero is the gen zeros kind of like the the easy stuff okay so that tells us something but what does it really tell us not a ton because this is all information without context and that's where i get into next is how to give this context because that could be fine or it could be horrific and which it is depends on if this is a well-written method or not and we can't really tell that on its own so we'll get there in just a minute this last thing right here is allocated and allocated down here this little legend is nice allocated memory per single operation not per thousand per single operation managed only and it's inclusive one kilobyte equals 1024 bytes so this is how much allocated memory is or how much memory is allocated per method call so when you call the method it's going to put some things in memory and if you look let's raise over a minute if you look down here we'll see we have this string output we also have this integer i these things are stored in memory and then this output gets sent back so these are memory uh usages of our application plus the fact that if you've watched some previous videos of mine and know about strings like that i had a video on things like three different things you need to know about strings one of them is that they're very expensive and this is a pretty expensive way of appending strings so this right here tells us that we're using 23 kilobytes of memory again is that good or is it bad well it's we don't know it's in a vacuum we don't know if this is a good method or not so now it's time to write another method and compare the two so we understand are our changes making any impact let's do that so now we're gonna write a a new method so let's come down here we're gonna say public string get full string with string builder all right that's a long name but it tells us what it's doing so instead of doing it this way we're going to instead of say string builder ctrl dot to add the using for system.text and we'll call this output equals new i'm gonna say new string builder here um we don't have to use new stringbuilder but i'm going to i'm gonna talk that in a little bit so four i is less than 100 make sure make sure that the the two numbers are the same so we're comparing apples to apples as much as possible output dot append i and then down here we're going to say return output dot to string okay so let's make sure that we're even bringing it back to a full string therefore we are doing full apples to apples comparison between the two different ways of doing strings now we're going to do is add a benchmark at the top here so we have now have a benchmark on two different methods so let's run this not with the run right here we can um actually can't sorry uh we can do a drop down right here and say control f5 or click this button so let's run this again and this time it's going to run two different methods so found two benchmarks in total it's going to run both of those sorry the fonts a little small i had to zoom it back a little bit in order to get all the text on the screen fully these benchmarks can get a little verbose in their width of what they're showing off in order to see the um that full table so this is going to run now it's going to run both of our methods and it's going to show us what each of them uses for the average time run the average memory consumed and the garbage collections per thousand for both gen 0 and gen 1. so right now we have our get full string normally that takes 2.984 microseconds which is actually a little better um but now notice that get full string with string builder second line takes 1.071 microseconds it's almost three times as fast as get full string normally we can ignore the the error and standard deviation they're going to be pretty much in line now gen zero calls 2.8343 for the first one versus 0.1678 i mean it's not even running one full gen zero call per 1000 calls the method that's much more memory efficient the gen 1 calls there are no gen 1 calls for the string builder version doesn't need them so therefore this is a much more efficient way of calling that same string method notice the end here allocated memory 23 kilobytes versus one kilobyte you've saved a tremendous about amount of memory and this is why i say that that seeing these things in a vacuum or on their own can give you some information but doesn't give you a full picture what it gives you is just information about the method and roughly if it's it's going to take up a lot of memory or not and take a lot of time or not it's not going to tell you if it's efficient or not because it may be efficient or it may be like in this case it's not and not only that okay this saved us basically three times the time so it's a third uh or three times as fast as the normal get full string method but that's not the whole picture because we're using that memory uh as well that's uh what's it called a memory diagnoser as well we also get the garbage collection information which tells us that it's much more efficient and much more easy on our garbage collector which means that less processing times be taken but it's also much better for our memory so this information can make a lot of impact in your decision making about which way you go with a certain method if your tweaks make sense or if they actually negatively impact your application again this is a comparison on my machine so right now here are the stats in which this will be the case these these numbers but does it really matter because if this is the difference 23 kilobytes versus one kilobyte that's going to be the same or similar on other machines the amount of garbage collection that will be different but this ratio probably won't be it'll be pretty close to the same so the ratio is what's important but what we don't have here is a good ratio comparison so let's add that so in this benchmark right here this is the normal version we can say hey this is the version we have in our code right now we're thinking about adding this will it make an impact well we already know it will but let's do a comparison more easily we're going to say in here baseline equals true and what this does is it says okay this is the method to base everything against and maybe you have three different versions of this or four different versions but this is the one that you want to do the comparison against now i'm not going to add a lot of methods here let's run this right away we'll talk more about this i'm not going to add a lot of methods here to test against like doing string interpolation and other things because that's not really the point of comparing all these different ones you can do that if you wanted to test different tweaks but the more methods you add the longer this takes and this is going to get to be a little bit longer than i want to show on video so i don't want to keep adding to it and make it too long so but what this is going to do now is it's going to run both those like before but this time it's going to say okay the the gold standard the the one we're going to compare against is that first one the normal way of doing things so now we have this new column here called ratio and the ratio says hey get full string normally that's the benchmark or that's the default therefore this is the baseline sorry that's the baseline therefore that's 1.0 and this one down here in comparison to the the baseline this is 0.36 anything less than 1 means it's better anything more than one means it's less than or not as good as the benchmark uh baseline so with that we now see that this is about three times almost three times as good as the normal version that's what that's doing is to the mean and saying hey compare that to this so even that ratio just note that it's not taking into account things like memory allocation because obviously the uh string builder version is about 23 times as good so this would be a ratio of 1 2.03 roughly um or i'm sorry zero to five ish um so that would be a different ratio but this ratio right here at least tells us hey compare these two numbers because if it's close that's going to tell you that if you have five or six different versions at glance you can see hey which is the smallest number that's the one i want to look at most intently so that is the comparison using benchmark.net for two methods but we're not done yet because right now we're doing a comparison on.net five specifically.net 5.0.9 but what if you want to compare this to other versions of net well fortunately we can run our console app on net framework and other platforms as well let's do that so let's do a comparison we're going to take off this baseline here we're going to add it in a different spot i'm going to do now is i'm going to say above memory diagnoser i'm going to say this is a simple job with a runtime moniker and that runtime moniker is going to be dot whoops that's a capital r right there ctrl dot here to add using benchmark.net.jobs um dot and we're going to say let's do net uh 4.8 this is where a little confusion is going to come in if you haven't watched my my video on dev questions about the different versions of net i would highly encourage you to check that out otherwise this might be even more confusing um what this is going to do is we're going to compare compare.net framework 4.8 let's do a copy here to net 5.0 now you have to have the net version installed on your machine the the sdk which you can get from microsoft if you don't have them installed but i have both of these dotnet 48 and net 5 both installed on my oops let's do net sorry i've had probably.net four eight let's do net uh 472 so i don't think i have.net for eight install i have 472 installed though sorry so i have both of these installed so let's compare net472.net 5. and again if you haven't watched that video on dev questions i'd highly encourage it but these are not that close it may look like oh the version difference is just a little bit no this is net framework this is net core that is about four years difference in the comparison maybe five um but this is dot net framework 4.7.2 this is dotnet core which is now has been named.net.net5 so it's a big difference in comparison now we also want to say that dot net 4 7 is the benchmark so let's put a comma after here and say benchmark or i'm sorry baseline i keep saying benchmark baseline is true and this will make the dotnet 4 7 version of the method calls the baseline so with that we're almost done but we're not done yet we do have to modify our project because right now our project builds for dotnet five which is net core dot net five we don't build for net framework four seven two we can change that by right clicking on our benchmark project or benchmark project and say edit project file this opens up the um the project file which is very small now which is very fortunate we don't have to go through a lot of different flags in here but in here we're going to change this from target framework to target frameworks plural both the the beginning and the end and now after net 50 we can put a semicolon and say net 472 which is dotnet framework 4.72 or 4.7.2 so this is going to come double compiler application and it's going to create the ability to benchmark both of those now we got a bunch of uh warnings and errors at the top here don't worry about those the first one says hey one or more projects have changed we've got to go ahead and reload the project cool the second one is that the um the release any cpu configuration is empty we'll need to do a nougat restore okay not a problem so let's hit reload project let's do a build rebuild solution not build solution rebuild solution there we go and we can enable intellicode that's fine we can close out of this error message we can close out the intellicode so what does the rebuild project do what does it clears everything out and it starts over so when you build things it tries to do shortcuts in order to make the build time faster with a rebuild it's going to clean out those folders and then it's going to build everything from the ground up again so with that now let's go to start without debugging and it's going to run our benchmarks again it found four benchmarks this time not two why four well it's going to run both methods in net framework 472 and it's going to run both methods again in net 5. so this is going to take twice as long as the well not quite twice as long but it's going to take more time than it has been taken before in fact it might actually be a little bit longer because of the net framework now some of you have heard me talk about net framework versus.net core this is going to highlight one of the big deals about why it's very important to move the dotnet core or why it's very beneficial i guess it's a better way of saying that it's very very beneficial to move.net core our code is not going to change between net framework and net core our actual c-sharp code is not going to change but we are going to see a difference in how fast that code runs and how efficient that code is so i want you to notice this when we look at the benchmarks because it's not just about whether we have our our normal version versus a stream builder we're gonna see that not only is our um let's maximize this here not only is our normal versus our string builder more efficient but dot net core is as well so this is the notice that the ratio is for net core framework versus.net core so the top line here the top two lines are get full string normally the top line is net 5 the second line is dotnet framework 472 so the average is 3 microseconds 4.net 5 normally 4.net framework the average is 7.4 microseconds double the time now look at the gen zero we're just going to look at this first two for a minute gen04.net 5 is 2.8 calls per thousand for net framework is 3.8 almost 3.9 calls per thousand for gen 1 it's 0 or 0.0038 versus .0076 so it's much more efficient to run the same method in net five versus dot net framework even though it's an inefficient method now look at the allocation the allocation is actually a little better uh one kilobyte different for net core versus.net framework let's go down to the string builder so dot net 5 we can see the 1 micro second but then notice that compare that with net framework it's 5 micro seconds so i want to do a quick comparison here look at the string builder version and net framework versus the regular version in.net 5. the stringbuilder version in.net framework is 5.8 microseconds the regular version.net core 5 is 3 microseconds it's actually almost twice as fast to run the exact to run the get full string normally in.net 5 versus the string builder version in.net framework so just by upgrading to net five you can actually have even poor methods outperform optimized methods in net framework all right so some cool comparison we can see here but also notice that for the stringbuilder method notice that the ratio framework versus core it's 0.18 in net 5. it's improved by almost over five times in performance yes the memory usage for the dot net framework version is more efficient than even the dot net five regular but it's four kilobytes versus one kilobyte in dot net five so it's three or four times more efficient memory wise for nat five with a string builder versus versus.net framework 4.7.2 so this gives us a lot more insight into how our application is going to execute again we can't look at just and say okay this method is going to take one microsecond that's on this machine okay that's with with these things being true but we can say is that the string builder is more efficient than normally and that the dotnet 5 version of stream builder is much more efficient than anything else whether it's the dotnet framework version of stringbuilder or the even.net 5 version of normally so we can see that upgrading our code to.net 5 will have a significant performance boost over just using a.net framework both in terms of memory allocation and as far as speed it's almost a six times speed increase it's over five times the speed increase um to just upgraded.net five with this method but not only that we also see that's better than this other method even if it is in dot net five so that gives us a lot of different comparison tools to look at and yes you won't want to compare everything all at once because most likely you're going to be looking at either is the upgrade worth it upgrade to.net core well in that case you wouldn't need to have these two methods being compared you could compare just one of them to the two frameworks or you'd be looking at is this version of the method better than the other version in which case you wouldn't need the different frameworks but i wanted you to see all of that all at once because i think it gives you a good perspective on how benchmarking works on why looking at different ways of doing a method are important because i mean this method is more efficient than this method even if you're in the same version.net 5 but also looking at why it's important to upgrade net core because even just doing from this efficient method from net framework to.net core you're going to be over five times as fast again your mileage may vary so you'd have to benchmark your own code and go oh hey we can save you know 40 of our time or we can save 30 of our memory usage whatever it is those will probably better than that but you're gonna see what exactly is you're gonna save by going to it and that can give you the case for why a change in method is important like hey i know it's going to take some time to do a testing and make sure it works and all the rest but i think it's worth it because it's going to go it's going to save us a bunch of memory allocation okay so we can really reduce how much memory is being used in the server or it can tell us hey you know what we need to bump from dotnetframe to.net 5. i know that it seems like nothing's going to happen but it's a real big memory difference it's going to be a huge speed improvement and really the code doesn't have to change that much now of course yes the code's going to change some because you have to change dependencies and all the rest but with this tool you can really give some numbers behind your your ideas but not only that it can give you a good idea of is a refactor even valuable so maybe you say hey you know what instead of doing let's close this out we've seen these numbers enough um instead of doing this um maybe we're doing this right now we'll say hey you know what instead of doing that let's let's do something like this where we come over here we say output equals um you know string interpolation then we'll say output and then we'll say i that's that's more readable it's not but maybe we think it is okay well you could benchmark these two different ways and go and we're not saving anything we're maybe even hurting ourselves a little bit um that gives you a better perspective on that so just being able to do those two different things will give you an idea of is this change valuable from an application standpoint maybe you run the method and go hey i know this is using an awful lot of memory what can i do to reduce this memory usage may make some tweaks to it do a second method do the comparison go oh that didn't change the memory allocation at all or that really reduced the memory allocation it may be a little bit more funky looking but it's going to be more efficient for our memory this is a valuable fix again you can take hard numbers to your boss and say i have benchmarked this and this is a five times memory improvement bosses love to hear things like that especially if you can show that memory is not going from four kilobytes to one kilobyte but more like 24 kilobytes to one kilobyte because then you're like wow that's a big that's an actual impact on our system so with that you can say okay now we use this for a million customers a day or whatever your numbers are probably a million million a day but whatever it is you can do some math and say it looks like we'll probably save about this much memory and you can know that before you put it in a production and then you can watch the actual numbers verify or validate what you're seeing now make sure you check your estimates and don't overestimate but based upon your numbers here you have at least a start of good information about what kind of memory pressures you can relieve or what kind of garbage collection you can reduce and so on so that's benchmark.net there's a lot of things you can do that if you want more information on benchmark.net you can go to benchmark.net.org which is confusing so let's look at it real quick here i'm going to zoom in here so benchmark dot d-o-t-n-e-t dot org that's the url you can go to i'll link that down the description but at this place you can see more information about you can even see how to run these charts and show us off but that's really just um one extra line let's see right here our r plot exporter there you go and with that you get these nice charts that you can play around with and see your benchmarks in more living color okay and not only that there's also more docs in here about um let's go to the articles right here um there's more documentation on the features statistics disassembler and so on you can go in a lot more detail about how this works what you can do tweak it even some samples for a number of different things on how to get these things to work so benchmark benchmark.net.org is the place to go to get all your information about benchmark.net it's a great tool to use to learn and to take advantage of one quick note though before i go just be careful because when you're benchmarking it's running your application a lot around your methods a lot so when it does that make sure that you are prepared for it for example if i had in here database code make sure your database is ready to handle that many inserts or reads or whatever it's going to do and that's not going to mess up your database don't do it against a production database or if you do make sure you can roll back or have good backups and the same thing with api if you're not calling api that rapidly make sure that you can call that rapidly you're not going to run into things like getting locked out because of too many calls and so on so be very careful not to make this a system stress test that you don't want to have run but do run your code against this try different things test out various pieces of your application usually the logic pieces the pieces where they're running on their own not um not pieces that are requiring ui interaction and things like that that's something different this is for the actual c sharp code itself that's running on its own you can test it against each other and see if you can come up with a more efficient version or or how a change to let's say uh net five versus dot net framework 472 might interact all right so that is the the demo i do want to move this over so let's i'm going to select demo hit ctrl dot and say i want to move type to demo.cs there we go so now it's much more in line what i would like to see from a project which is that every class has its own file so there we go i'll give this source code to you they'll be linked down the description you can get fill your email address and i will email it to you right away and if you have thoughts on benchmark.net leave them down in the comments if you have questions about it if you want to see more of that garbage collector leave those comments down in the comments below this video as well i'd love to hear your thoughts thanks for watching as always i am tim cory [Music] [Applause] you
Info
Channel: IAmTimCorey
Views: 15,057
Rating: undefined out of 5
Keywords: .net, C#, Visual Studio, code, programming, tutorial, course, training, how to, tim corey, C# training, C# tutorial, .net core
Id: mmza9x3QxYE
Channel Id: undefined
Length: 52min 14sec (3134 seconds)
Published: Mon Aug 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.