-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark module, remove SquarifiedMeasurer2
- Loading branch information
Showing
9 changed files
with
173 additions
and
239 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
plugins { | ||
alias(libs.plugins.android.test) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "com.example.benchmark" | ||
compileSdk = properties["android.compileSdk"].toString().toInt() | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.toVersion(properties["jvm.version"].toString()) | ||
targetCompatibility = JavaVersion.toVersion(properties["jvm.version"].toString()) | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = properties["jvm.version"].toString() | ||
} | ||
|
||
defaultConfig { | ||
minSdk = properties["android.minSdk"].toString().toInt() | ||
targetSdk = properties["android.targetSdk"].toString().toInt() | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR" | ||
} | ||
|
||
buildTypes { | ||
// This benchmark buildType is used for benchmarking, and should function like your | ||
// release build (for example, with minification on). It"s signed with a debug key | ||
// for easy local/CI testing. | ||
create("benchmark") { | ||
isDebuggable = true | ||
// isMinifyEnabled = true | ||
signingConfig = getByName("debug").signingConfig | ||
matchingFallbacks += listOf("release") | ||
} | ||
} | ||
|
||
targetProjectPath = ":sample:android" | ||
experimentalProperties["android.experimental.self-instrumenting"] = true | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.test.ext.junit) | ||
implementation(libs.androidx.test.espresso.core) | ||
implementation(libs.ui.automator) | ||
implementation(libs.macrobenchmark.junit) | ||
} | ||
|
||
androidComponents { | ||
beforeVariants(selector().all()) { | ||
it.enable = it.buildType == "benchmark" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest /> |
103 changes: 103 additions & 0 deletions
103
benchmark/src/main/java/com/example/benchmark/TreemapChartBenchmark.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.example.benchmark | ||
|
||
import androidx.benchmark.macro.CompilationMode | ||
import androidx.benchmark.macro.FrameTimingMetric | ||
import androidx.benchmark.macro.MacrobenchmarkScope | ||
import androidx.benchmark.macro.StartupMode | ||
import androidx.benchmark.macro.junit4.MacrobenchmarkRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.Until | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class TreemapChartBenchmark { | ||
|
||
@get:Rule | ||
val benchmarkRule = MacrobenchmarkRule() | ||
|
||
@Test | ||
fun showSimpleChart() = measureRepeated { | ||
startActivityAndWait() | ||
|
||
device.wait(Until.hasObject(By.text("4")), 1000) | ||
device.wait(Until.hasObject(By.text("2")), 1000) | ||
device.wait(Until.hasObject(By.text("1")), 1000) | ||
} | ||
|
||
@Test | ||
fun showComplexChart() = benchmarkRule.measureRepeated( | ||
packageName = "by.overpass.treemapchart.sample.android", | ||
metrics = listOf(FrameTimingMetric()), | ||
compilationMode = CompilationMode.DEFAULT, | ||
startupMode = StartupMode.COLD, | ||
iterations = 5, | ||
) { | ||
startActivityAndWait() | ||
|
||
device.findObject(By.text("Show more complex chart")) | ||
.click() | ||
|
||
device.wait( | ||
Until.hasObject( | ||
By.text( | ||
""" | ||
|Cars | ||
|12.11% | ||
""".trimMargin(), | ||
), | ||
), | ||
5000, | ||
) | ||
} | ||
|
||
@Test | ||
fun showComplexChartDetailPopup() = benchmarkRule.measureRepeated( | ||
packageName = "by.overpass.treemapchart.sample.android", | ||
metrics = listOf(FrameTimingMetric()), | ||
compilationMode = CompilationMode.DEFAULT, | ||
startupMode = StartupMode.COLD, | ||
iterations = 5, | ||
) { | ||
startActivityAndWait() | ||
|
||
device.findObject(By.text("Show more complex chart")) | ||
.click() | ||
|
||
device.wait( | ||
Until.hasObject( | ||
By.text( | ||
""" | ||
|Cars | ||
|12.11% | ||
""".trimMargin(), | ||
), | ||
), | ||
5000, | ||
) | ||
device.findObject( | ||
By.text( | ||
""" | ||
|Cars | ||
|12.11% | ||
""".trimMargin(), | ||
), | ||
).click() | ||
|
||
device.wait(Until.hasObject(By.text("Exports value")), 5000) | ||
device.wait(Until.hasObject(By.text("$88.6B")), 5000) | ||
} | ||
|
||
private fun measureRepeated(block: MacrobenchmarkScope.() -> Unit) { | ||
benchmarkRule.measureRepeated( | ||
packageName = "by.overpass.treemapchart.sample.android", | ||
metrics = listOf(FrameTimingMetric()), | ||
compilationMode = CompilationMode.DEFAULT, | ||
startupMode = StartupMode.COLD, | ||
iterations = 5, | ||
measureBlock = block, | ||
) | ||
} | ||
} |
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
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
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
Oops, something went wrong.