Skip to content

Commit

Permalink
Add benchmark module, remove SquarifiedMeasurer2
Browse files Browse the repository at this point in the history
  • Loading branch information
overpas committed Oct 20, 2024
1 parent 166523b commit cebd185
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 239 deletions.
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions benchmark/build.gradle.kts
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"
}
}
1 change: 1 addition & 0 deletions benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
103 changes: 103 additions & 0 deletions benchmark/src/main/java/com/example/benchmark/TreemapChartBenchmark.kt
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,
)
}
}
8 changes: 7 additions & 1 deletion sample/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ android {
isDebuggable = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
// create("benchmark") {
create("benchmark") {
initWith(buildTypes.getByName("release"))
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("release")
isDebuggable = false
}
// create("benchmark") {
// initWith(release)
// signingConfig = signingConfigs.getByName("debug")
// matchingFallbacks.add("release")
Expand Down
7 changes: 6 additions & 1 deletion sample/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="by.overpass.treemapchart.sample.android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:supportsRtl="true"
android:theme="@style/AppTheme">
<profileable android:shell="true" />
<profileable
android:shell="true"
tools:targetApi="29" />

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include(":treemap-chart")
include(":treemap-chart-compose")
include(":sample:shared")
include(":sample:android")
//include(":sample:android:macrobenchmark")
include(":sample:desktop")
include(":sample:web")
include(":sample:web-wasm")
include(":benchmark")
Loading

0 comments on commit cebd185

Please sign in to comment.