I want to test my Custom component UI rendering performance. I used the following test case to check the rendering performance.
private long getLayoutTime(int layoutRes) {
final Context targetContext = getInstrumentation().getTargetContext();
final LayoutInflater layoutInflater = LayoutInflater.from(targetContext);
final long startTime = System.currentTimeMillis();
for (int i = 0; i < 1000; i++) {
final View view = layoutInflater.inflate(layoutRes, null);
view.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
view.measure(View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
final int measuredHeight = view.getMeasuredHeight();
final int measuredWidth = view.getMeasuredWidth();
view.layout(0, 0, measuredWidth, measuredHeight);
}
return System.currentTimeMillis() - startTime;
}
Using of this code I can test the layout render timing. So that I changed the layout design for better performance. Now I am creating a Custom view class with multiple layouts and components like images, textviews and etc. I will attach the class at run time and components will create on the run time based on the server response. I will not attach this custom component in XML. Now I want to test the rendering performance of this custom view. Please suggest me any tools or any way to calculate the UI rendering time for the custom view.
from How to test the Custom view performance
No comments:
Post a Comment