Permalink
Browse files

BNRTimeBlock

  • Loading branch information...
1 parent 909e2bb commit 9afe1e14583d3823de174e737ef4a5b39a27911a @mxcl committed Mar 19, 2012
Showing with 20 additions and 0 deletions.
  1. +17 −0 BNRTimeBlock.m
  2. +2 −0 MBCategories.h
  3. +1 −0 MBCategories.m
View
17 BNRTimeBlock.m
@@ -0,0 +1,17 @@
+#import <mach/mach_time.h> // for mach_absolute_time() and friends
+
+// reference: http://weblog.bignerdranch.com/?p=316
+
+CGFloat BNRTimeBlock(void (^block)(void)) {
+ mach_timebase_info_data_t info;
+ if (mach_timebase_info(&info) != KERN_SUCCESS) return -1.0;
+
+ uint64_t start = mach_absolute_time ();
+ block ();
+ uint64_t end = mach_absolute_time ();
+ uint64_t elapsed = end - start;
+
+ uint64_t nanos = elapsed * info.numer / info.denom;
+ return (CGFloat)nanos / NSEC_PER_SEC;
+
+}
View
2 MBCategories.h
@@ -5,6 +5,8 @@
#import "NSURLConnection+mxcl.h"
#import "NSThread+mxcl.H"
+CGFloat BNRTimeBlock(void (^block)(void));
+
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#import "MBActionSheet.h"
#import "UIAlertView+mxcl.h"
View
1 MBCategories.m
@@ -1,3 +1,4 @@
+#import "BNRTimeBlock.m"
#import "NSArray+mxcl.m"
#import "NSObject+mxcl.h"
#import "NSNumber+mxcl.m"

0 comments on commit 9afe1e1

Please sign in to comment.