Linked Questions
45 questions linked to/from Is DateTime.Now the best way to measure a function's performance?
87
votes
4
answers
118k
views
What is the best way to measure execution time of a function? [duplicate]
Obviously I can do and DateTime.Now.After - DateTime.Now.Before but there must be something more sophisticated.
Any tips appreciated.
69
votes
5
answers
43k
views
.NET Stopwatch - performance penalty [duplicate]
Possible Duplicates:
Is DateTime.Now the best way to measure a function's performance?
Stopwatch vs. using System.DateTime.Now for timing events
I have code which needs to run as fast as ...
16
votes
4
answers
41k
views
C# - Calculating time difference in minutes [duplicate]
I have got the following code:
DateTime start = DateTime.Now;
Thread.Sleep(60000);
DateTime end = DateTime.Now;
and I would like to calculate the difference in minutes between start and end. How am I ...
7
votes
3
answers
20k
views
how to set timer for calculate execution time [duplicate]
i like to set timer for calculating execution time in c# for particular process in my execution. how can i do this
1
vote
2
answers
1k
views
C# TimeSpan gives 0 as TotalMilliseconds [duplicate]
I was trying to "benchmark" two nearly identical loops. When I inspect them one by one the subtraction is without any hiccups, and the TimeSpan gives back the correct numbers as the TotalMilliseconds. ...
1
vote
1
answer
933
views
best way to check performance of the code in C# [duplicate]
We are working on two different libraries which tends to perform the same work. I have been assigned to check which library performs the same work faster with given set of inputs. there are multiple ...
3
votes
1
answer
1k
views
Calculate time consumption of query [duplicate]
I have a select query, i would like to run it 50 times in parallel(to load test) ie. 50 independent times(a separate process).
if i run like this
for (int i=0;i<=49;i++)
{
//record start time ...
-2
votes
4
answers
154
views
How can I time how long it takes a small block of C# code to execute? [duplicate]
I have this code:
var userId = Int32.Parse(User.Identity.GetUserId());
using (var context = new IdentityContext())
{
roleId = context.Database.SqlQuery<int>("SELECT RoleId FROM ...
0
votes
2
answers
59
views
Precision timing using DateTime possible? [duplicate]
I would like to test the time required by certain methods and SQL queries in my code. I've tried doing the following:
DateTime start = DateTime.Now;
//Do something
DateTime end = DateTime.Now;
...
2182
votes
20
answers
756k
views
How do I profile C++ code running on Linux? [closed]
How do I find areas of my code that run slowly in a C++ application running on Linux?
743
votes
9
answers
777k
views
Calculate the execution time of a method
I have an I/O time-taking method which copies data from a location to another. What's the best and most real way of calculating the execution time? Thread? Timer? Stopwatch? Any other solution? I want ...
510
votes
6
answers
462k
views
LINQ .Any VS .Exists - What's the difference?
Using LINQ on collections, what is the difference between the following lines of code?
if(!coll.Any(i => i.Value))
and
if(!coll.Exists(i => i.Value))
When I disassemble .Exists, it looks like ...
148
votes
7
answers
198k
views
Measuring code execution time in this code
I want to know how much time a procedure/function/order takes to finish, for testing purposes.
This is what I did, but my method is wrong, because if the difference of seconds is 0, it can't return ...
79
votes
14
answers
94k
views
Environment.TickCount vs DateTime.Now
Is it ever OK to use Environment.TickCount to calculate time spans?
int start = Environment.TickCount;
// Do stuff
int duration = Environment.TickCount - start;
Console.WriteLine("That took "...
52
votes
18
answers
30k
views
How to measure code performance in .NET?
I'm doing some real quick and dirty benchmarking on a single line of C# code using DateTime:
long lStart = DateTime.Now.Ticks;
// do something
long lFinish = DateTime.Now.Ticks;
The problem is in the ...