Created
May 21, 2014 19:38
-
-
Save mdznr/80c5d334e196317c0486 to your computer and use it in GitHub Desktop.
Is there a speed difference between [UIColor colorWithRed:green:blue:alpha:] and [UIColor colorWithHue:saturation:brightness:alpha:]?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat red = 0.08f; | |
CGFloat green = 0.49f; | |
CGFloat blue = 0.98f; | |
CGFloat hue = 0.59f; | |
CGFloat saturation = 0.92f; | |
CGFloat brightness = 0.98f; | |
CGFloat alpha = 1.0f; | |
uint64_t t_0 = dispatch_benchmark(iterations, ^{ | |
@autoreleasepool { | |
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; | |
} | |
}); | |
NSLog(@"[UIColor colorWithRed:green:blue:alpha:] Avg. Runtime: %llu ns", t_0); | |
uint64_t t_1 = dispatch_benchmark(iterations, ^{ | |
@autoreleasepool { | |
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha]; | |
} | |
}); | |
NSLog(@"[UIColor colorWithHue:saturation:brightness:alpha:] Avg. Runtime: %llu ns", t_1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nope. The results fluctuate, but it doesn't seem like there a faster method, which is good. Pick whichever method makes more sense to you when reading your source code.