I would like to detect how fast is the device on which my Android application is running?
Is there any API to do it on Android? Or do I have to benchmark it by mysel
Based on @dogbane solution and this answer, this is my implementation to get the BogoMIPS value:
/**
* parse the CPU info to get the BogoMIPS.
*
* @return the BogoMIPS value as a String
*/
public static String getBogoMipsFromCpuInfo(){
String result = null;
String cpuInfo = readCPUinfo();
String[] cpuInfoArray =cpuInfo.split(":");
for( int i = 0 ; i< cpuInfoArray.length;i++){
if(cpuInfoArray[i].contains("BogoMIPS")){
result = cpuInfoArray[i+1];
break;
}
}
if(result != null) result = result.trim();
return result;
}
/**
* @see {https://stackoverflow.com/a/3021088/3014036}
*
* @return the CPU info.
*/
public static String readCPUinfo()
{
ProcessBuilder cmd;
String result="";
InputStream in = null;
try{
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
} catch(IOException ex){
ex.printStackTrace();
} finally {
try {
if(in !=null)
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}