How can i stress my phone's CPU programatically?

前端 未结 3 1850
终归单人心
终归单人心 2021-01-05 07:08

So i overclocked my phone to 1.664ghz and I know there are apps that test your phone\'s CPU performance and stressers but I would like to make my own someway. What is the be

3条回答
  •  走了就别回头了
    2021-01-05 08:10

    To compile a regex string:

    Pattern p1 = Pattern.compile("a*b"); // a simple regex
    // slightly more complex regex: an attempt at validating email addresses
    Pattern p2 = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
    

    You need to launch these in background threads:

    class RegexThread extends Thread {
       RegexThread() {
          // Create a new, second thread
          super("Regex Thread");
          start(); // Start the thread
       } 
    
       // This is the entry point for the second thread.
       public void run() {
          while(true) {
            Pattern p = Pattern.compile("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b");
          }
       }
    }
    
    class CPUStresser {
       public static void main(String args[]) {
          static int NUM_THREADS = 10, RUNNING_TIME = 120; // run 10 threads for 120s
          for(int i = 0; i < NUM_THREADS; ++i) {
             new RegexThread(); // create a new thread
          }
          Thread.sleep(1000 * RUNNING_TIME);
       }
    }
    

    (above code appropriated from here)

    See how that goes.

提交回复
热议问题