Flutter Analysis and Practice: Cross-End Solution Performance Comparison

4.4.1 Cross-End Solution Comparison

4.4.1.1 Comparison

4.4.1.2 Scenarios

4.4.1.3 Test Tools

  • Testing on mobile phones (iOS): CPU and memory Instruments: FPS
  • ADB-based Shell script (Android): CPU, memory, and FPS

4.4.1.4 Testing Models

  • iOS: iPhone 5C (iOS 9.0.1) and iPhone 6S (iOS 10.3.2)
  • Android: Xiaomi Mi 2S (Android 5.0.2) and Samsung Galaxy S8 (Android 7.0)

4.4.2 Data Analysis and Comparison

4.4.2.1 iOS

Figure 4–14
Figure 4–15

4.4.2.2 Android

Figure 4–16
Figure 4–17

4.4.3 Summary

4.4.4 More Information

  • Run dumpsys meminfo packageName to obtain the memory usage on Android
  • Run the top command through busybox to obtain the CPU utilization on Android
  • Accumulate the CPU utilization of each thread to obtain the total CPU utilization on iOS
for (j = 0; j < thread_count; j++)
{
ATCPUDO *cpuDO = [[ATCPUDO alloc] init];
char name[256];
pthread_t pt = pthread_from_mach_thread_np(thread_list[j]);
if (pt) {
name[0] = '\0';
__unused int rc = pthread_getname_np(pt, name, sizeof name);
cpuDO.threadid = thread_list[j];
cpuDO.identify = [NSString stringWithFormat:@"%s",name];
}
thread_info_count = THREAD_INFO_MAX;
kr = thread_info(thread_list[j], THREAD_BASIC_INFO,(thread_info_t)thinfo, &thread_info_count);
if (kr != KERN_SUCCESS) {
return nil;
}
basic_info_th = (thread_basic_info_t)thinfo;
if (!(basic_info_th->flags & TH_FLAGS_IDLE)) {
tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;
tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;
tot_cpu = tot_cpu + basic_info_th->cpu_usage / (float)TH_USAGE_SCALE * 100.0;
cpuDO.usage = basic_info_th->cpu_usage / (float)TH_USAGE_SCALE * 100.0;
if (container) {
[container addObject:cpuDO];
}
}
} // for each thread
  • To obtain the memory usage on iOS, use physfootprint during the test, which is the most accurate physical memory. However, residentsize (the resident memory usage, which cannot show the real memory changes) is used for many open-source apps.
if ([[UIDevice currentDevice].systemVersion intValue] < 10) {
kern_return_t kr;
mach_msg_type_number_t info_count;
task_vm_info_data_t vm_info;
info_count = TASK_VM_INFO_COUNT;
kr = task_info(mach_task_self(), TASK_VM_INFO_PURGEABLE, (task_info_t)&vm_info,&info_count);
if (kr == KERN_SUCCESS) {
return (vm_size_t)(vm_info.internal + vm_info.compressed - vm_info.purgeable_volatile_pmap);
}
return 0;
}
task_vm_info_data_t vmInfo;
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
if (result != KERN_SUCCESS)
return 0;
return (vm_size_t)vmInfo.phys_footprint;

Original Source:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com