Add short notation for benchmarking #7

Closed
MattesGroeger opened this Issue Apr 8, 2013 · 7 comments

Projects

None yet

2 participants

@MattesGroeger
Owner

If you just have one session to measure at a time this macros would be even simpler to use:

benchmark_start("session name")
benchmark_step("step name")
benchmark_total()
benchmark_finish()
@workwithnano
Contributor

This is the macro setup that I use, with the intention of placing all steps at the end of any function which demarcates a "step".

#define BenchStart(__SESSION__) [MGBenchmark start:__SESSION__]
#define BenchStep(__SESSION__) [[MGBenchmark session:__SESSION__] step:[NSString stringWithFormat:@"%@ %@", [self class], NSStringFromSelector(_cmd)]]
#define BenchTotal(__SESSION__) [[MGBenchmark session:__SESSION__] total]
#define BenchEnd(__SESSION__) [[MGBenchmark session:__SESSION__] total];[MGBenchmark finish:__SESSION__]
#ifndef DEBUG
    #define BenchStart(__SESSION__) do {} while (0)
    #define BenchStep(__SESSION__) do {} while (0)
    #define BenchTotal(__SESSION__) do {} while (0)
    #define BenchEnd(__SESSION__) do {} while (0)
#endif

The step method prints out the class name followed by the objective-c method the call was made from.

@MattesGroeger
Owner

Hey @workwithnano, that is great! Would you like to create a pull request for that?

@workwithnano
Contributor

I'll do that if you think it's a good setup. It works for me very nicely, but it makes some assumptions about where you're going to use the macros.

@MattesGroeger
Owner

Would it be possible to pass an (optional) string for BenchStep. Only if that one is not defined it would use class and selector. Or we could have two versions BenchStep(__SESSION__, __STEP__) and BenchStepMethod(__SESSION__). What do you think?

@workwithnano
Contributor

I think the first one works. I'll whip it up and I'll also include a fix I created for simultaneous/nested benchmarking (since right now the benchmarktarget can only ever reference one session).

@MattesGroeger
Owner

Sounds great! Thanks already for your contribution!

@MattesGroeger
Owner

Added to 0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment