Skip to content

Instantly share code, notes, and snippets.

@mdznr
Created May 21, 2014 19:38
Show Gist options
  • Save mdznr/80c5d334e196317c0486 to your computer and use it in GitHub Desktop.
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:]?
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);
@mdznr
Copy link
Author

mdznr commented May 21, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment