Latest 0.1.0
License MIT
Platforms ios 7.0, requires ARC

Time blocks of code to identify performance bottlenecks.


Wrap the code you want to time in +[XINBlockTimer timeBlock:].

#import "XINBlockTimer.h"

// manually build an attributed string

[XINBlockTimer timeBlock:^{

  NSString *rawText = @"This is some bold text.";

  NSRange range = [rawText rangeOfString:@"bold"];

  NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  paragraphStyle.alignment = NSTextAlignmentCenter;

  NSDictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyle, 
                               NSFontAttributeName: [UIFont systemFontOfSize:fontSize]};
  NSMutableAttributedString *text;
  text = [[NSMutableAttributedString alloc] initWithString:rawText attributes:attributes];

  label.attributedText = text;


You can also name each block, which shows up in the output.

[XINBlockTimer timeBlock:^{

  // For example: time creating an attributed string with HTML //
  NSString *html = @"<style>p {font: 12px HelveticaNeue; text-align: center;}</style>"
                   @"<p>This is some <b>bold</b> text.</p>";

  NSDictionary *optionsDict = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)};
  NSAttributedString *text = [[NSAttributedString alloc] initWithData:

  label2.attributedText = text;

} withName:@"attributed string from HTML"];

Output via NSLog:

XINBlockTimer: 0.000381 sec
attributed string from HTML: 0.174494 sec

If you keep the returned NSTimeIntervals, you can pass them to a reporting method that summarizes your findings.

NSTimeInterval t1 = [XINBlockTimer timeBlock:^{ ... }];
NSTimeInterval t2 = [XINBlockTimer timeBlock:^{ ... }];

[XINBlockTimer compareTimeInterval:t1 withTimeInterval:t2];

Sample Output:

First interval is 457.989501x faster
Difference between intervals is insignificant: 0.000002

See the enclosed example project for more usage examples.


XINBlockTimer is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "XINBlockTimer",
    "version": "0.1.0",
    "license": "MIT",
    "summary": "Time blocks of code to identify performance bottlenecks",
    "homepage": "",
    "authors": {
        "Jason Moore": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.1.0"
    "requires_arc": true,
    "platforms": {
        "ios": "7.0"
    "source_files": "XINBlockTimer/*.{h,m}",
    "public_header_files": "XINBlockTimer/*.h"

Pin It on Pinterest

Share This