|
| 1 | +/* |
| 2 | + * Copyright 2021 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.samples.apps.iosched.macrobenchmark |
| 18 | + |
| 19 | +import androidx.benchmark.macro.StartupMode |
| 20 | +import androidx.benchmark.macro.junit4.MacrobenchmarkRule |
| 21 | +import androidx.test.filters.LargeTest |
| 22 | +import org.junit.Rule |
| 23 | +import org.junit.Test |
| 24 | +import org.junit.runner.RunWith |
| 25 | +import org.junit.runners.Parameterized |
| 26 | + |
| 27 | +@LargeTest |
| 28 | +@RunWith(Parameterized::class) |
| 29 | +class StartupBenchmark(private val startupMode: StartupMode) { |
| 30 | + @get:Rule |
| 31 | + val benchmarkRule = MacrobenchmarkRule() |
| 32 | + |
| 33 | + @Test |
| 34 | + fun startup() = benchmarkRule.measureStartup( |
| 35 | + profileCompiled = false, |
| 36 | + startupMode = startupMode, |
| 37 | + iterations = 3 |
| 38 | + ) { |
| 39 | + action = "com.google.samples.apps.iosched.STARTUP_ACTIVITY" |
| 40 | + } |
| 41 | + |
| 42 | + companion object { |
| 43 | + @Parameterized.Parameters(name = "mode={0}") |
| 44 | + @JvmStatic |
| 45 | + fun parameters(): List<Array<Any>> { |
| 46 | + return listOf(StartupMode.COLD, StartupMode.WARM, StartupMode.HOT) |
| 47 | + .map { arrayOf(it) } |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments