-
-
Save madisp/31a298d191380d8a721c042d217fc36f to your computer and use it in GitHub Desktop.
Android CPU perf tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
import static java.math.BigInteger.ONE; | |
import org.junit.Test; | |
import java.math.BigInteger; | |
import java.util.stream.Stream; | |
public class CpuPerfTests { | |
public static final int NUM_COUNT = 200000; | |
public static final int CERTAINTY = 50; | |
@Test | |
public void computePrimes_singlethread() { | |
BigInteger sum = Stream.iterate(ONE, (x) -> x.add(ONE)) | |
.filter(x -> x.isProbablePrime(CERTAINTY)) | |
.limit(NUM_COUNT) | |
.reduce(BigInteger::add) | |
.get(); | |
assertEquals(new BigInteger("264129169599"), sum); | |
} | |
@Test | |
public void computePrimes_multithread() { | |
BigInteger sum = Stream.iterate(ONE, (x) -> x.add(ONE)) | |
.parallel() | |
.filter(x -> x.isProbablePrime(CERTAINTY)) | |
.limit(NUM_COUNT) | |
.reduce(BigInteger::add) | |
.get(); | |
assertEquals(new BigInteger("264129169599"), sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment