Just published a NSObject category, MKBlockTimer.
Use this nifty utility to measure the time taken to execute a block of code, without macros.

Usage

The method is fairly straightforward to use.

  [self logTimeTakenToRunBlock:^{
 
    // your time consuming piece of code here
    for(int i = 0 ; i < 1000000000; i ++);
 
  } withPrefix:@"For Loop"];

When you do this, you should see the following on the console.

Output

2013-04-04 22:07:08.966 MKBlockTimerDemo[69436:c07] For Loop: 1814 ms

The method logs the time taken to execute the block on the console with a specified prefix. You can pass any string for prefix and use it to identify the block. I’ve been using this for quite sometime and thought would open source it. I find this method much clearer than manually adding startTimer and endTimer methods and hope it would be useful for you too.

Source Code

The code is available under MIT license at the Github repository MKBlockTimer


Mugunth

Follow me on Twitter

  • Gary Morris

    Nice idea!