Visual Studio time complexity

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi all,

Is there a way for visual studio to show the time complexity (for the Big-O notation) of each line?

I am determining the Big-O notation complexity of a loop, but for most line I don't know their actual complexity value.

Examples are:
Item tempItem = stkList;
Console.ReadLine();
Console.Clear();
tax = ((taxRate / 100) * price) + price;

How can I determine their equivalence complexity value please?
 

kubeek

Joined Sep 20, 2005
5,795
I doubt that. You would have to analyze the program by yourself to find out. For example tax = ((taxRate / 100) * price) + price; is surely O(1)
 

WBahn

Joined Mar 31, 2012
30,058
Time complexity is an asymptotic description of how long a computation takes as the number of things, or the size of the set, being computed grows without bound. So when you have a loop that is, say, determining the tax charged for the sale of N items, what you want to do is first ask whether or not how long each pass through the loop takes is in anyway dependent on the number of items. Probably not. So this has O(1), namely it takes a constant amount of time independent of the number of items. Exactly how long it takes is immaterial because, in the limit that N goes to infinity, any process that has higher than constant complexity, say O(N), will eventually take longer than any O(1) process for some value of N (and greater).
 

vpoko

Joined Jan 5, 2012
267
The easiest way is to put a counter inside your innermost loop and check its value after the loops exit. Time complexity only makes sense if you're looping, iteratively or recursively. And like WBahn said, this won't tell you the actual asymptotic complexity since that would require running the loop forever and looking at the growth rate, but it will tell you the practical (finite) complexity of your loops.
 
Top