Cómo detectar la velocidad de la cpu de Android?


Me gustaría detectar qué tan rápido es el dispositivo en el que se está ejecutando mi aplicación Android?

¿Hay alguna API para hacerlo en Android? ¿O tengo que compararlo yo solo?

Si el dispositivo tiene una CPU lenta, me gustaría desactivar algunas operaciones que consumen mucho tiempo, como animaciones o limitar el número máximo de solicitudes HTTP simultáneas.

Author: Dariusz Bacinski, 2011-02-02

4 answers

La mejor manera de hacerlo en mi opinión es monitorear el tiempo que toma hacer estas acciones. Si está tomando demasiado tiempo, entonces el sistema es demasiado lento y puede desactivar las características de lujo hasta que sea lo suficientemente rápido.

Leer la velocidad de la CPU u otras especificaciones e intentar juzgar la velocidad del sistema es una mala idea. Los futuros cambios en el hardware podrían hacer que estas especificaciones no tengan sentido.

Mira el Pentium 4 vs el Core 2 por ejemplo. Que es la CPU más rápida, un Pentium 4 de 2.4 GHz, o el 1.8 GHz Core 2? ¿Es un Opteron de 2 GHz más rápido que un Itanium 2 de 1,4 GHz? ¿Cómo vas a saber qué tipo de CPU ARM es realmente más rápido?

Para obtener clasificaciones de velocidad del sistema para Windows Vista y 7 Microsoft realmente compara la máquina. Este es el único método medio preciso para determinar las capacidades del sistema.

Parece que un buen método es usar SystemClock.uptimeMillis ().

 25
Author: Zan Lynx,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-03 15:11:43

Intenta leer /proc/cpuinfo que contiene información de la cpu:

   String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
   ProcessBuilder pb = new ProcessBuilder(args);

   Process process = pb.start();
   InputStream in = process.getInputStream();
   //read the stream
 8
Author: dogbane,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-02 14:22:25

Basado en la solución @ dogbane y esta respuesta , esta es mi implementación para obtener el valor de BogoMips:

 /**
 * 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;
}
 2
Author: ahmed_khan_89,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:09:36

Por favor, consulte el siguiente enlace que proporcionará los datos relacionados con la CPU

 1
Author: chiranjib,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-12 20:55:12