Performance Measurement of .NET Code
In .NET we often come across scenarios where we need to find out how much time the code takes to execute, and find the exact location in the code where the performance is not good.
Especially when you are working customer facing applications like website or webservices.
Avoid Using DateTime
When I was new in development, I was using datetime most of the time. I was using the following code to check the execution time:
The above code works fine but its not very accurate.
I was working on a project where I was using CLR Store proc in SQL Server 2008 to call a webservice. I put the above code around it to
find out the execution time. It was taking about 400ms to execute the code. But in when I found the execution time for the store proc itself
in t-sql, it was taking about 1.4 second. At that time I realised that using DateTime is not a reliable method to find the execution time.
Use Stopwatch
As an alternative to this, I found that the .NET Framework already has a Stopwatch which is more accurate than DateTime.
I replaced my code with stopwatch and it give me accurate execution time.
___________________________________________________________________
Mitul Patel
http://dot-net-solutions.blogspot.com/
http://www.omkarsolutions.com.au/
___________________________________________________________________
I recommend the following books to improve your code performance.
This blog is created to help people find solutions to their daily .NET programming needs. It also has tips and tricks to do clever programming in C#
Friday, 3 September 2010
Performance Measurement of .NET Code
Labels:
.net performance measurement
Thursday, 2 September 2010
Splitting string with deliminator In SQL Server
During my work I came to a problem where I had to extract some numbers from a comma
separated list of numbers in TSQL 2008 (Sql Server).
I had to extract last seven numbers from a comma separated list of 14 numbers.
Just for the start I created a table function called ufn_Split.
This function takes two arguments:
1. Data
2. Deliminator
And it returns the split data in a tabular format.
Below is the function :
___________________________________________________________________
Mitul Patel
___________________________________________________________________
I recommend the following books to improve your T-SQL Skills.
Labels:
split function,
sql server
Subscribe to:
Posts (Atom)