summaryrefslogtreecommitdiff
path: root/apct-tests
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2024-01-29 14:59:52 +0000
committerVictor Chang <vichang@google.com>2024-01-29 15:15:34 +0000
commitb1bf611b59d19d628d94deab3a25c3cf73bbc111 (patch)
tree0ebc62037e4a0c96f593ca0199b7d1da0ddbfd2f /apct-tests
parentc40bde3f8e0b3fd98f3ae0579770b9947322c229 (diff)
downloadbase-b1bf611b59d19d628d94deab3a25c3cf73bbc111.tar.gz
Avoid mockito in MotionPredictorBenchmark
Mockito dominates the time to create MotionPredictor, and it can be avoided. The median time reduces from ~39614ns to ~683ns. (-98%). Bug: 321913450 Test: atest CorePerfTests:android.input.MotionPredictorBenchmark Change-Id: Idea21b5627a25af8d5941bb8c7a1ff567eb2504d
Diffstat (limited to 'apct-tests')
-rw-r--r--apct-tests/perftests/core/src/android/input/MotionPredictorBenchmark.kt23
1 files changed, 3 insertions, 20 deletions
diff --git a/apct-tests/perftests/core/src/android/input/MotionPredictorBenchmark.kt b/apct-tests/perftests/core/src/android/input/MotionPredictorBenchmark.kt
index aadbc2319a62..add0a086201b 100644
--- a/apct-tests/perftests/core/src/android/input/MotionPredictorBenchmark.kt
+++ b/apct-tests/perftests/core/src/android/input/MotionPredictorBenchmark.kt
@@ -16,8 +16,6 @@
package android.input
-import android.content.Context
-import android.content.res.Resources
import android.os.SystemProperties
import android.perftests.utils.PerfStatusReporter
import android.view.InputDevice
@@ -38,8 +36,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
-import org.mockito.Mockito.mock
-import org.mockito.Mockito.`when`
import java.time.Duration
@@ -68,18 +64,6 @@ private fun getStylusMotionEvent(
InputDevice.SOURCE_STYLUS, /*flags=*/0)
}
-private fun getPredictionContext(offset: Duration, enablePrediction: Boolean): Context {
- val context = mock(Context::class.java)
- val resources: Resources = mock(Resources::class.java)
- `when`(context.getResources()).thenReturn(resources)
- `when`(resources.getInteger(
- com.android.internal.R.integer.config_motionPredictionOffsetNanos)).thenReturn(
- offset.toNanos().toInt())
- `when`(resources.getBoolean(
- com.android.internal.R.bool.config_enableMotionPrediction)).thenReturn(enablePrediction)
- return context
-}
-
@RunWith(AndroidJUnit4::class)
@LargeTest
class MotionPredictorBenchmark {
@@ -115,7 +99,7 @@ class MotionPredictorBenchmark {
var eventPosition = 0f
val positionInterval = 10f
- val predictor = MotionPredictor(getPredictionContext(offset, /*enablePrediction=*/true))
+ val predictor = MotionPredictor(/*isPredictionEnabled=*/true, offset.toNanos().toInt())
// ACTION_DOWN t=0 x=0 y=0
predictor.record(getStylusMotionEvent(
eventTime, ACTION_DOWN, /*x=*/eventPosition, /*y=*/eventPosition))
@@ -141,12 +125,11 @@ class MotionPredictorBenchmark {
*/
@Test
fun timeCreatePredictor() {
- val context = getPredictionContext(
- /*offset=*/Duration.ofMillis(20), /*enablePrediction=*/true)
+ val offsetNanos = Duration.ofMillis(20).toNanos().toInt()
val state = perfStatusReporter.getBenchmarkState()
while (state.keepRunning()) {
- MotionPredictor(context)
+ MotionPredictor(/*isPredictionEnabled=*/true, offsetNanos)
}
}
}