Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de33bb18 authored by Miguel Aranda's avatar Miguel Aranda Committed by Gerrit Code Review
Browse files

Merge "Migrate libcore benchmarks to BenchmarkRule" into main

parents d2d6e53f e292bf87
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.libcore;

import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -34,11 +34,11 @@ import org.junit.runner.RunWith;
public class AdditionPerfTest {

    @Rule
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
    public BenchmarkRule mBenchmarkRule = new BenchmarkRule();

    @Test
    public void timeAddConstantToLocalInt() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        int result = 0;
        while (state.keepRunning()) {
            result += 123;
@@ -46,7 +46,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddTwoLocalInts() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        int result = 0;
        int constant = 123;
        while (state.keepRunning()) {
@@ -55,7 +55,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddConstantToLocalLong() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        long result = 0;
        while (state.keepRunning()) {
            result += 123L;
@@ -63,7 +63,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddTwoLocalLongs() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        long result = 0;
        long constant = 123L;
        while (state.keepRunning()) {
@@ -72,7 +72,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddConstantToLocalFloat() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        float result = 0.0f;
        while (state.keepRunning()) {
            result += 123.0f;
@@ -80,7 +80,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddTwoLocalFloats() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        float result = 0.0f;
        float constant = 123.0f;
        while (state.keepRunning()) {
@@ -89,7 +89,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddConstantToLocalDouble() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        double result = 0.0;
        while (state.keepRunning()) {
            result += 123.0;
@@ -97,7 +97,7 @@ public class AdditionPerfTest {
    }
    @Test
    public void timeAddTwoLocalDoubles() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        double result = 0.0;
        double constant = 123.0;
        while (state.keepRunning()) {
+7 −7
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.libcore;

import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -33,11 +33,11 @@ import java.util.Arrays;
public class ArrayCopyPerfTest {

    @Rule
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
    public BenchmarkRule mBenchmarkRule = new BenchmarkRule();

    @Test
    public void timeManualArrayCopy() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        char[] src = new char[8192];
        while (state.keepRunning()) {
            char[] dst = new char[8192];
@@ -49,7 +49,7 @@ public class ArrayCopyPerfTest {

    @Test
    public void time_System_arrayCopy() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        char[] src = new char[8192];
        while (state.keepRunning()) {
            char[] dst = new char[8192];
@@ -59,7 +59,7 @@ public class ArrayCopyPerfTest {

    @Test
    public void time_Arrays_copyOf() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        char[] src = new char[8192];
        while (state.keepRunning()) {
            char[] dst = Arrays.copyOf(src, 8192);
@@ -68,7 +68,7 @@ public class ArrayCopyPerfTest {

    @Test
    public void time_Arrays_copyOfRange() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        char[] src = new char[8192];
        while (state.keepRunning()) {
            char[] dst = Arrays.copyOfRange(src, 0, 8192);
+6 −6
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.libcore;

import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -38,7 +38,7 @@ public class ArrayIterationPerfTest {
    }

    @Rule
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
    public BenchmarkRule mBenchmarkRule = new BenchmarkRule();

    Foo[] mArray = new Foo[27];
    {
@@ -46,7 +46,7 @@ public class ArrayIterationPerfTest {
    }
    @Test
    public void timeArrayIteration() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            int sum = 0;
            for (int i = 0; i < mArray.length; i++) {
@@ -56,7 +56,7 @@ public class ArrayIterationPerfTest {
    }
    @Test
    public void timeArrayIterationCached() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            int sum = 0;
            Foo[] localArray = mArray;
@@ -69,7 +69,7 @@ public class ArrayIterationPerfTest {
    }
    @Test
    public void timeArrayIterationForEach() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            int sum = 0;
            for (Foo a: mArray) {
+5 −5
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.libcore;

import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -39,7 +39,7 @@ public class ArrayListIterationPerfTest {
        int mSplat;
    }
    @Rule
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
    public BenchmarkRule mBenchmarkRule = new BenchmarkRule();

    ArrayList<Foo> mList = new ArrayList<Foo>();
    {
@@ -47,7 +47,7 @@ public class ArrayListIterationPerfTest {
    }
    @Test
    public void timeArrayListIterationIndexed() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            int sum = 0;
            ArrayList<Foo> list = mList;
@@ -59,7 +59,7 @@ public class ArrayListIterationPerfTest {
    }
    @Test
    public void timeArrayListIterationForEach() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            int sum = 0;
            for (Foo a : mList) {
+10 −9
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.libcore;

import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -38,7 +38,8 @@ import java.math.BigInteger;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class BigIntegerPerfTest {
    @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
    @Rule
    public BenchmarkRule mBenchmarkRule = new BenchmarkRule();

    // A simple sum of products computation, mostly so we can check timing in the
    // absence of any division. Computes the sum from 1 to n of ((10^prec) << 30) + 1)^2,
@@ -61,7 +62,7 @@ public class BigIntegerPerfTest {
    // Execute the above rep times, optionally timing it.
    @Test
    public void repeatInner() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            for (int i = 10; i <= 10_000; i *= 10) {
                inner(100, i);
@@ -85,7 +86,7 @@ public class BigIntegerPerfTest {
    // Check results for equality, and print one, to compaare against reference.
    @Test
    public void repeatHarmonic1000() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            for (int i = 5; i <= 5_000; i *= 10) {
                BigInteger refRes = harmonic1000(i);
@@ -106,7 +107,7 @@ public class BigIntegerPerfTest {
    // us to time and check it for consistency as well.
    @Test
    public void repeatToString() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            for (int i = 5; i <= 5_000; i *= 10) {
                BigInteger refRes = harmonic1000(i);
@@ -146,7 +147,7 @@ public class BigIntegerPerfTest {
    // to compare to reference.
    @Test
    public void repeatEApprox() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            for (int i = 10; i <= 10_000; i *= 10) {
                BigInteger refRes = eApprox(100_000, i);
@@ -165,7 +166,7 @@ public class BigIntegerPerfTest {
    // Test / time modPow()
    @Test
    public void repeatModPow() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            for (int i = 5; i <= 500; i *= 10) {
                BigInteger odd1 = BigInteger.TEN.pow(i / 2).add(BigInteger.ONE);
@@ -198,7 +199,7 @@ public class BigIntegerPerfTest {
    // Test / time modInverse()
    @Test
    public void repeatModInverse() {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final BenchmarkState state = mBenchmarkRule.getState();
        while (state.keepRunning()) {
            for (int i = 10; i <= 10_000; i *= 10) {
                BigInteger odd1 = BigInteger.TEN.pow(i / 2).add(BigInteger.ONE);
Loading