Fixed
Status Update
Comments
cc...@google.com <cc...@google.com> #2
Parsing out the name would be dependent on the parameterization string. I'm used to that same naming convention you mention, so it may generalize fine. In fact, looking at all the parameterization in the AndroidX repo, it looks doable - internal convention is comma separated, with either an '=' or ':' delimiting key and value. So e.g. mapping would be:
"foo:10" ->
[foo, 10]
"foo=something,bar=somethingelse" ->
[foo, something]
[bar, somethingelse]
"x:10,x:20" ->
[x, 10]
[x, 20]
"foo:10,bar=20" ->
[foo, 10]
[bar, 20]
"10, 20, 30" ->
[{0}, 10]
[{1}, 20]
[{2}, 30]
Which is trivial to do:
listOf(
"foo:10",
"foo=something,bar=somethingelse",
"x:10,x:20",
"foo:10,bar=20",
"10, 20, 30"
).forEach {
println("\"$it\" ->")
it.split(",").forEachIndexed { i, string ->
val index = string.lastIndexOfAny(charArrayOf('=', ':'))
val result = if (index >= 0) {
listOf(string.substring(0, index).trim(), string.substring(index + 1).trim())
} else {
listOf("{$i}", string.trim())
}
println(" $result")
}
}
It's just a question of how well that generalizes to other users of parameterized.
"foo:10" ->
[foo, 10]
"foo=something,bar=somethingelse" ->
[foo, something]
[bar, somethingelse]
"x:10,x:20" ->
[x, 10]
[x, 20]
"foo:10,bar=20" ->
[foo, 10]
[bar, 20]
"10, 20, 30" ->
[{0}, 10]
[{1}, 20]
[{2}, 30]
Which is trivial to do:
listOf(
"foo:10",
"foo=something,bar=somethingelse",
"x:10,x:20",
"foo:10,bar=20",
"10, 20, 30"
).forEach {
println("\"$it\" ->")
it.split(",").forEachIndexed { i, string ->
val index = string.lastIndexOfAny(charArrayOf('=', ':'))
val result = if (index >= 0) {
listOf(string.substring(0, index).trim(), string.substring(index + 1).trim())
} else {
listOf("{$i}", string.trim())
}
println(" $result")
}
}
It's just a question of how well that generalizes to other users of parameterized.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 60bf74f157926d6ce860f1d9c91b735bd414346b
Author: Sergey <zakharovsergey1000@gmail.com>
Date: Wed Jul 10 14:06:20 2019
Include parameterized parameters in dedicated section in json output
Internal convention is comma separated list of parameters, with
either an '=' or ':' delimiting key and value of parameter.
Bug: 132578772
Test: ./gradlew benchmark:cC
Change-Id: I9dddb62eec853b1d9e6bbab33c2c37304658155e
M benchmark/benchmark/src/androidTest/java/androidx/benchmark/benchmark/ParameterizedBenchmark.kt
M benchmark/common/build.gradle
M benchmark/common/src/androidTest/java/androidx/benchmark/ResultWriterTest.kt
M benchmark/common/src/main/java/androidx/benchmark/ResultWriter.kt
https://android-review.googlesource.com/1013669
https://goto.google.com/android-sha1/60bf74f157926d6ce860f1d9c91b735bd414346b
Branch: androidx-master-dev
commit 60bf74f157926d6ce860f1d9c91b735bd414346b
Author: Sergey <zakharovsergey1000@gmail.com>
Date: Wed Jul 10 14:06:20 2019
Include parameterized parameters in dedicated section in json output
Internal convention is comma separated list of parameters, with
either an '=' or ':' delimiting key and value of parameter.
Bug: 132578772
Test: ./gradlew benchmark:cC
Change-Id: I9dddb62eec853b1d9e6bbab33c2c37304658155e
M benchmark/benchmark/src/androidTest/java/androidx/benchmark/benchmark/ParameterizedBenchmark.kt
M benchmark/common/build.gradle
M benchmark/common/src/androidTest/java/androidx/benchmark/ResultWriterTest.kt
M benchmark/common/src/main/java/androidx/benchmark/ResultWriter.kt
Description
```
@RunWith(Parameterized::class)
class Benchmark(val size: Long) {
companion object {
@JvmStatic
@Parameterized.Parameters(name = "size={0}")
fun data(): Array<Long> {
return arrayOf(10, 100, 1000);
}
}
@get:Rule
val benchmarkRule = BenchmarkRule()
@Test
fun myBenchmark() {
benchmarkRule.measureRepeated {
for(i in 0 until size) {
// Do work
}
}
}
}
```
The output will look something like this
```
{ "results": [
{
"name": "myBenchmark[size=10]",
"classname": "com.test.benchmark.Benchmark",
"nanos": 279000,
"warmupIterations": 652,
"repeatIterations": 1,
"runs": [ ... ]
}
}
```
While it is possible to parse the parameterized parameter from the `name` String it is annoying to have to do so. It would be much easier for further post-processing of the results if these parameters had their own block, something like:
```
// Figuring out that the parameter is named `size` would be awesome, but probably not straight forward
{ "results": [
{
"name": "myBenchmark[size=10]",
"params": {
size: 10
}
"classname": "com.test.benchmark.Benchmark",
"nanos": 279000,
"warmupIterations": 652,
"repeatIterations": 1,
"runs": [ ... ]
}
}
// This kind of output would still be easier to parse programmatically and is similar to how the parameterized runner approaches it.
{ "results": [
{
"name": "myBenchmark[size=10]",
"params": [10], // Create a parameter array that uses the `{x}` indexes from JUnit.
"classname": "com.test.benchmark.Benchmark",
"nanos": 279000,
"warmupIterations": 652,
"repeatIterations": 1,
"runs": [ ... ]
}
}
```