Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add short notation for benchmarking #7

MattesGroeger opened this Issue · 7 comments

2 participants


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")

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)

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


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


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.


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?


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).


Sounds great! Thanks already for your contribution!


Added to 0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.