如何通过程序来压力测试手机的CPU?

9

我将我的手机超频到1.664GHz,我知道有一些测试手机CPU性能和压力测试的应用程序,但我想自己制作一个。什么是让CPU真正工作的最佳方法?我想只需使用for循环执行100万次耗时数学计算...但这并没有奏效,因为我的手机在几毫秒内完成了操作...我尝试了数万亿次迭代...应用程序冻结了,但我的任务管理器并未显示该应用程序使用CPU。通常,压力测试应用程序会显示为红色,并显示CPU:85% RAM:10MB...那么我如何让处理器认真思考呢?


1
听起来你阻塞了“UI线程”。创建一个后台线程(或多个后台线程),并在其中放置一些“工作循环”——我猜测观察到的结果会有很大不同,但不知道是否能成功地压力测试CPU。(我不做Android开发。) - user166390
@davids0n,您能否解释或展示编译“regex”字符串的代码?可能需要在多个线程上运行? - Mohammad Adib
如果你想学习一些东西,这里有一些“正则表达式”:http://www.codeproject.com/KB/dotnet/regextutorial.aspx - Stefan Kendall
在循环内嵌套循环,并在其中创建二维矩阵。 - SidJ
@Sridhar...哇,那真是令人难以置信的 o.O - Mohammad Adib
显示剩余3条评论
3个回答

2
编译正则表达式字符串的方法如下:
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");

您需要在后台线程中启动这些内容:

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);
   }
}

(上述代码来源于这里)

看看效果如何。


1
非常感谢!我会在有时间的时候尝试一下!我猜Pattern是一个我不必自己创建的类?编辑:10个线程算多吗?会对我的CPU造成相当大的负担吗?哈哈,100个线程? - Mohammad Adib
Pattern是一个内置类。import java.util.regex.Pattern; 如果你想的话可以做100个线程,但是每个线程上的while(true)循环将会使CPU达到最大值。 - user244343
我不太明白你在这里做了什么:"[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" 这是我见过的最长的无意义字符串!哈哈 - Mohammad Adib

1
I would suggest a slightly different test, it is not a simple mathematical algorithm and function. There are plenty of odd-looking tests whose results always contain all reviews. You launch the application, it works for a while, and then gives you the result in standard scores. The more points (or less), it is considered that the device is better. But what the comparison results mean in real life is not always clear. And not all.
Regarding 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 the 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".

使用慢算法"亚伯拉罕·夏普级数"计算一千万个标记。多次重复测量,取平均值。

  1. 测试“愤怒的小鸟”

选择第一个版本的愤怒的小鸟(非必需,但这些版本不是最优化的)

从启动到第一次音乐声的时间。退出。立即再次运行。多次重复并取平均值。

  1. 测试“大页面”

测量重负载网页的加载时间。您可以使用您喜欢的浏览器 :)

您可以使用 此链接(很抱歉使用了西里尔文)

该页面与图片一起使用“计算机浏览器”进行维护。总共有6.5 Mb和99个文件(我仍然在这个页面上以其存储版本的小声音频文件)

将所有99个文件上传到手机。关闭Wi-Fi和移动互联网(这很重要!)

页面会在您的浏览器中打开。点击“返回”按钮。现在点击“前进”并测量页面完全加载的时间。然后再做几次。反向-前向,反向-前向。通常情况下,我们取平均值。

所有结果以秒为单位给出。

在测试期间,支持microSD卡的所有设备都使用同一张卡-Transcend 16 Gb,10级别。并且所有数据都在上面。

好的,这些设备的实际测试结果TEST RESULT


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接