How to get maximum CPU usage

I am currently testing hardware temperature tests, and I was wondering how you will do maximum performance. The task is that all 4 cores of my device are occupied in order to measure the maximum temperature?

I could, of course, start n threads with infinite loops, but I think there may be better ways to solve this problem.

while (true) { try { new Thread() { public void run() { while (true) { try { Runtime.getRuntime().exec("ps"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }.start(); } catch (Error e) { // typically will be OutOfMemoryerror during Thread alloc } } 

Also in your manifest:

 <application android:largeHeap="true" ... 

adb shell top :

 User 99%, System 0%, IOW 0%, IRQ 0% User 1216 + Nice 0 + Sys 4 + Idle 0 + IOW 0 + IRQ 0 + SIRQ 0 = 1220 PID PR CPU% S #THR VSS RSS PCY UID Name 3534 0 99% S 1292 1990880K 32784K fg u0_a56 com.myapp.cpupressure 

But it is still not as effective as AnTuTu stability:

temp curve

+6
source share
1 answer

You can try this multi-core test that will use all cores. And you can overload as you wish.

 public class MultiCore { private static final int SPIN_COUNT = 2000; public static void main(String[] args) { int numThreads = 4; if (args.length == 1) { numThreads = Integer.valueOf(args[0]); } System.out.println("Starting " + numThreads + " threads"); long startWhen = System.nanoTime(); SpinThread threads[] = new SpinThread[numThreads]; for (int i = 0; i < numThreads; i++) { threads[i] = new SpinThread(i); threads[i].start(); } for (int i = 0; i < numThreads; i++) { try { threads[i].join(); } catch (InterruptedException ie) { System.err.println("join " + i + " failed: " + ie); } } long endWhen = System.nanoTime(); System.out.println("All threads finished in " + ((endWhen - startWhen) / 1000000) + "ms"); } static class SpinThread extends Thread { private int mTid; SpinThread(int tid) { mTid = tid; } public void run() { long startWhen = System.nanoTime(); System.out.println("Thread " + mTid + " started"); int tid = mTid; int reps = SPIN_COUNT + tid; int ret = 0; for (int i = 0; i < reps; i++) { for (int j = 0; j < 100000; j++) { ret += i * j; } } long endWhen = System.nanoTime(); System.out.println("Thread " + mTid + " finished in " + ((endWhen - startWhen) / 1000000) + "ms (" + ret + ")"); } } } 
+1
source

Source: https://habr.com/ru/post/958133/


All Articles