Skip to content

Instantly share code, notes, and snippets.

@kirillp
Created February 15, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirillp/d567e98c306066d34bc3d4eeef497314 to your computer and use it in GitHub Desktop.
Save kirillp/d567e98c306066d34bc3d4eeef497314 to your computer and use it in GitHub Desktop.
package delightex.moe;
import apple.uikit.UIColor;
import delightex.graphics.moe.MoeCoreFoundation;
import delightex.graphics.moe.MoeObjC;
import delightex.graphics.moe.MoeUiKit;
import delightex.graphicsTest.performance.framework.PerfTest;
import delightex.graphicsTest.performance.framework.PerformanceFramework;
import delightex.tools.time.PerformanceTimer;
import static delightex.graphics.moe.MoeCoreFoundation.CFDictionaryGetValue;
import static delightex.graphics.moe.MoeUiKit.NSForegroundColorAttributeName;
public class UiColorTest {
public static String run(PerformanceTimer timer) {
long cfFontAttributes = MoeUiKit.createDictionaryMutable(); // NSMutableDictionary.alloc().init()
PerfTest<?>[] tests = {
useJavaUIColor(cfFontAttributes),
useNativeUIColor(cfFontAttributes)
};
String result = PerformanceFramework.run(10, tests, timer, "");
MoeCoreFoundation.CFRelease(cfFontAttributes);
return result;
}
private static PerfTest<String> useJavaUIColor(final long cfFontAttributes) {
return new PerfTest<String>() {
@Override
public String run() {
for (int i = 0; i < 1_000; i++) {
UIColor uiColor = UIColor.colorWithRedGreenBlueAlpha(
i / 1000.f, i / 800.f, i / 700.f, i / 600.f);
MoeUiKit.setForegroundColor(cfFontAttributes, uiColor);
}
long l = CFDictionaryGetValue(cfFontAttributes, NSForegroundColorAttributeName());
return MoeObjC.getClassName(MoeObjC.object_getClass(l));
}
@Override
public String toString() {
return "1k setForegroundColor Java";
}
};
}
private static PerfTest<String> useNativeUIColor(final long cfFontAttributes) {
return new PerfTest<String>() {
@Override
public String run() {
for (int i = 0; i < 1_000; i++) {
MoeObjC.setForegroundColor(cfFontAttributes,
i / 1000.f, i / 800.f, i / 700.f, i / 600.f);
}
long l = CFDictionaryGetValue(cfFontAttributes, NSForegroundColorAttributeName());
return MoeObjC.getClassName(MoeObjC.object_getClass(l));
}
@Override
public String toString() {
return "1k setForegroundColor native";
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment