-2

I want to compare the compute performance of an android device and a linux virtual machine. (part of my master thesis) The test must be use some kind of inputs (for example an image, or just numbers), and must have some outputs too.

For example a jar file to make a panorama picture of a few images. Or maybe a password cracker.

The other requirment is, that the test must be started programatically. So it must be possible, to start the panorama making or the password cracking with a java method call.

Is there an opensource project or a jar file to make this test?

UPDATE: The linked answer isn't what I searching for: @linski There are just ideas, no implementations. And it would be better if the tasks could be "real life" scenarios. For example get a big panorama picture, or crack a password.

UPDATE2: "The test must be use some kind of inputs (for example an image, or just numbers), and must have some outputs too." + "And it would be better if the tasks could be "real life" scenarios"

tamas.pflanzner
  • 325
  • 1
  • 6
  • 11
  • http://stackoverflow.com/questions/3693197/cpu-intensive-calculation-examples – linski Apr 07 '13 at 12:20
  • I would suggest you split your question as you are clearly looking for two separate answers. You say that starting the task should begin with a java method call. From where? The device itself or a separate machine? – Paul Lammertsma Apr 07 '13 at 12:37
  • 1
    What you want is to find a Java benchmark. There are probably several dozen "recognized" benchmarks, some designed for servers, though, and some incredibly trivial and hence invalid. Finding the right one (or several) will be your first task (keeping in mind that all benchmarks, especially Java benchmarks, are not representative of "real" performance). – Hot Licks Apr 07 '13 at 12:48
  • @PaulLammertsma I'm looking for just one thing: a compute intensive jar. The panorama making and password cracking are just examples. I want to call the method from my java code (runs on the same device) – tamas.pflanzner Apr 07 '13 at 13:13
  • @duffymo Thank you for your comment, it's really helpful... You should read the question a few more times to understand it :) – tamas.pflanzner Apr 07 '13 at 13:15
  • @HotLicks I want something that shows the power of cloud computing. A task, that runs long enough on an android device to worth it to run in the cloud. – tamas.pflanzner Apr 07 '13 at 13:18
  • If processor cycles has your focus, I suggest you take a look at the linked question. Otherwise, you may have to reformulate your question. – Paul Lammertsma Apr 07 '13 at 13:24
  • @linski There are just ideas, no implementations. And it would be better if the tasks could be "real life" scenarios. For example get a big panorama picture, or crack a password. – tamas.pflanzner Apr 07 '13 at 13:26

1 Answers1

10

This Fibonnaci sequence got all 4 of my cores up to near 100%:

public static BigInteger fib(BigInteger n) {
    if (n.compareTo(BigInteger.ONE) == -1 || n.compareTo(BigInteger.ONE) == 0 ) return n;
    else 
        return fib(n.subtract(BigInteger.ONE)).add(fib(n.subtract(BigInteger.ONE).subtract(BigInteger.ONE)));
}

public static void main(String[] args) {
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    for (int j = 0; j < 10; j++) {
        final int ID = j;
        executorService.submit(new Runnable() {

            public void run() {
                for (int i=0;i < Integer.MAX_VALUE; i++) {
                    System.out.println(ID+" worker: "+i + ": " + fib(new BigInteger(String.valueOf(i))));
                }
            }
        });
    }        
}

That's most probably not good enough for benchmarking: enter image description here

but it took 15 mins to write, and it is CPU intensive. Regarding to the real life example, read HotLicks comment. So if you want the password cracker here is the most unefficient way to find a prime number, which is the essential operation in breaking RSA:

public static boolean isPrime(BigInteger n) {
    BigInteger counter = BigInteger.ONE.add(BigInteger.ONE);
    boolean isPrime = true;
    while (counter.compareTo(n) == -1) {
        if (n.remainder(counter).compareTo(BigInteger.ZERO) == 0) {
            isPrime = false;
            break;
        }
        counter = counter.add(BigInteger.ONE);
    }
    return isPrime;
}

public static void main(String[] args) {
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    for (int j = 0; j < 10; j++) {
        final int ID = j;
        executorService.submit(new Runnable() {
            public void run() {
                BigInteger number = BigInteger.ONE;
                while(true) {
                    System.out.println(ID+" worker: "+number + ": " + isPrime(number));
                    number = number.add(BigInteger.ONE);
                }
            }
        });
    }        
}

It is less CPU intensive than Fibonnaci:

enter image description here

Probably because Fibonnaci has recursive calls.

The linked answer is a list of problems that are known to be CPU intensive. It even has RSA challenge mentioned.

Community
  • 1
  • 1
linski
  • 5,046
  • 3
  • 22
  • 35