0

Example of what I'm looking for in pseudocode:

time = functionimlookingfor(arbitraryfunction(inputs));

The reason I'm trying to find something like this is so I can get a graph of the algorithmic time complexity of a function. I'm pretty new to programming, so if there's already something out there for this that'd also be great.

My idea was just to run an arbitrary function such as a sort repeatedly with random numbers, each time increasing the amount of random numbers, while an array of vectors keeps track of the count and time to completion for each run. Then I'd be able to use this array of vectors to graph the size vs. time. Also open to any better ideas for accomplishing this.

Austin
  • 6,921
  • 12
  • 73
  • 138
  • Unfortunately, it can't exist as a function because functions do not get to choose how their arguments are evaluated. I hope the linked question is helpful in solving your problem. (Or at least, it can't exist as a function with the semantics you specified in the question.) – Dietrich Epp Feb 13 '16 at 02:27
  • It's fairly straightfoward when you're familiar with variadic templates and perfect forwarding to make a `time_it(foo, arg1, arg2, ..., argN)` interface and add `` timing code around the call. – chris Feb 13 '16 at 02:27
  • 1
    http://www.cplusplus.com/reference/chrono/high_resolution_clock/now/ – macroland Feb 13 '16 at 02:33
  • I think that link is what I'm looking for, thanks – Austin Feb 13 '16 at 02:36

0 Answers0