How can i stress my phone's CPU programatically?

若如初见. 提交于 2019-11-30 20:41:01

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.

I would suggest a slightly different test, it is not a simple mathematical algorithms and functions. There are plenty of odd-looking tests whose results always contains all reviews. You launch the application, it works for a while, and then gives you the result in standard scores. The more points more (or less), it is considered that the device better. But that the comparison results mean in real life, is not always clear. And not all. Regard to mathematics, the first thing that comes to mind is a massive amount of counting decimal places and the task to count the number "pi"

OK. No problem, we will do it:

Here's a test number one - "The Number Pi" - how long it takes your phone to calculate the ten million digits of Pi (3.14) (if someone said this phrase a hundred years ago, exactly would be immediately went to a psychiatric hospital)

When you feel that the phone is slow. You turn / twist interface. But how to measure it - it is unclear. Angry Birds run on different devices at different times - perhaps test "Angry Birds"

We think further - get a couple more tests, "heavy book" and "a large page."

algorithm of calculation:

  1. Test "of Pi"

Take the Speed Pi. Count ten million marks by using a slow algorithm "Abraham Sharp Series. Repeat measurements several times, take the average.

  1. Test "Angry Birds"

Take the very first Angry Birds (not required, but these versions are not the most optimized)

Measure the time from launch to the first sounds of music. Exit. Immediately run over and over again. Repeat several times and take the average.

  1. Test "Large Page"

Measure the load time of heavy site pages. You can do it with your favorite browser :)

You can use This link (sorry for the Cyrillic)

This page is maintained by using "computers browser" along with pictures. Total turns out 6.5 Mb and 99 files (I'm still on this page in its stored version of a small sound file)

All 99 files upload to the phone. Turn off Wi-Fi and mobile Internet (this is important!)

Page opens with your browser. Click the "back" button. And now click "Forward" and measure the time the page is fully loaded. And so a few times. Back-forward, backward-forward. As usual, we take the average.

All results are given in seconds.

During testing all devices that support microSD cards, was one and the same card-Transcend 16 Gb, class 10. And all data on it.

Well, the actual results of the tests for some devices TEST RESULT

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!