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 best way to really make your CPU work? I was thinking just making a for loop do 1 million iterations of doing some time-consuming math...but that did not work becuase my phone did it in a few milliseconds i think...i tried trillions of iterations...the app froze but my task manager did not show the cpu even being used by the app. Usually stress test apps show up as red and say cpu:85% ram: 10mb ...So how can i really make my processor seriously think?
-
Make sure that the compiler is not optimizing away your loop entirely. For example, if you never use the result of a calculation the compiler will almost certainly just remove it completely. – Ed S. Sep 13 '11 at 04:24
-
1It sounds like you killed (are blocking indefinitely) the "UI thread". Make a background (or a number of background) threads and put some "work loops" in those -- I suspect the observed results will be a good bit different, but do not know if that will succeed in stressing the CPU. (I do no Android development.) – Sep 13 '11 at 04:24
-
How do i run multiple threads and how do i use my result but not show it to the user?? Just do thread.start() a bunch of times? Sorry im good at Java but never dealt with threads in my life lol. – Mohammad Adib Sep 13 '11 at 04:30
-
Launch background threads which compile millions of regex strings. That's pretty tough on CPU, from personal experience. – Sep 13 '11 at 04:31
-
@davids0n Can you please explain or show code which compiles "regex" strings?? possibly on multiple threads? – Mohammad Adib Sep 13 '11 at 04:32
-
In case you feel like doing some learning, here's some "regex": http://www.codeproject.com/KB/dotnet/regextutorial.aspx – Stefan Kendall Sep 13 '11 at 04:59
-
Loop within loops and creating a two dimensionsal matrix in them. – SidJ Sep 13 '11 at 05:01
-
@Sridhar...whoa that's mindboggling o.O – Mohammad Adib Sep 13 '11 at 05:15
3 Answers
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.
-
1Thanks a bunch! Will give it a try when i get time! I'm guessing Pattern is a class i won't have to make? EDIT: is 10 threads a lot? What would be quite a cumbersome burden on my CPU? lol 100 threads? – Mohammad Adib Sep 13 '11 at 05:07
-
Pattern is a built-in class. `import java.util.regex.Pattern;` You can do 100 threads if you want to, but it's the `while(true)` loop on each of the threads that will max out CPU. – Sep 13 '11 at 05:12
-
I don't quite understand what you did here: "[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" That's the biggest gibberish string i've ever laid eyes on! lol – Mohammad Adib Sep 13 '11 at 05:12
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:
- 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.
- 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.
- 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

- 11
- 3
https://play.google.com/store/apps/details?id=xcom.saplin.xOPS - the app crunches numbers (integer and float) on multiple threads (2x number of cores) and builds performance and CPU temperature graphs.
https://github.com/maxim-saplin/xOPS-Console/blob/master/Saplin.xOPS/Compute.cs - that's the core of the app

- 4,115
- 38
- 29