Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions 30 docs/report-generators/expression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,36 @@ Which yields:
:language: bash
:section: 2


.. _generator_expression_derivations:

Derivations
-----------

:ref:`Expressions<generator_expression_expressions>` effectively enable you to
populate a *table* based on the benchmarking :ref:`data <generator_expression_data>`.
**Derivations** allow you to derive new columns from that table in one or more
passes.

Derivations have access to two variables and each expression is mapped on a row:

- ``table``: a data frame containing the entire table. ``table['mean']`` for example will yield a **list** containing all of the values in the `mean` column.
- ``row``: the current row to which the derivation will be mapped. ``row['mean']`` for example will yield the value of `mean` in the current row.

In the following example we derive a new column ``super mean``:

.. approved:: ../../examples/Command/report-generators-derivations
:language: javascript
:section: 0

Which yields:

.. approved:: ../../examples/Command/report-generators-derivations
:language: bash
:section: 2

.. _generator_expression_data:

Data
----

Expand Down
11 changes: 7 additions & 4 deletions 11 examples/Command/report-generators-column-diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
"my-report": {
"generator": "expression",
"aggregate": ["iteration_index"],
"cols": {
"subject": null,
"mode": null,
"diff": "format('%.2fx', mean(result_time_avg) / min(suite['result_time_avg']))"
"cols": [
"subject",
"mode",
"diff"
],
"derivations": {
"diff": "if(min(table['mode']) > 0, format('%.2fx', row['mode'] / min(table['mode'])), 'N/A')"
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions 22 examples/Command/report-generators-derivations
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"report.generators": {
"my-report": {
"generator": "expression",
"cols": [ "benchmark", "subject", "mode", "super mode" ],
"derivations": {
"super mode": "row['mode'] ~ ' of ' ~ sum(table['mode'])"
}
}
}
}
---
phpbench run --report=my-report --executor=debug MultipleSubjects.php --progress=none
---
+----------------------+---------------+----------+------------+
| benchmark | subject | mode | super mode |
+----------------------+---------------+----------+------------+
| MultipleSubjectBench | benchSubject1 | 10.000μs | 10 of 30 |
| MultipleSubjectBench | benchSubject2 | 10.000μs | 10 of 30 |
| MultipleSubjectBench | benchSubject3 | 10.000μs | 10 of 30 |
+----------------------+---------------+----------+------------+

6 changes: 3 additions & 3 deletions 6 examples/Command/report-generators-expressions
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"my-report": {
"generator": "expression",
"expressions": {
"mode": "\"This is the mode: \" ~ mode(result_time_avg)"
"new_mode": "\"This is the mode: \" ~ mode(result_time_avg)"
},
"cols": [ "benchmark", "subject", "mode" ]
"cols": [ "benchmark", "subject", "new_mode" ]
Comment thread
dantleech marked this conversation as resolved.
}
}
}
---
phpbench run --report=my-report --executor=debug NothingBench.php --progress=none
---
+--------------+--------------+----------------------+
| benchmark | subject | mode |
| benchmark | subject | new_mode |
+--------------+--------------+----------------------+
| NothingBench | benchNothing | This is the mode: 10 |
+--------------+--------------+----------------------+
Expand Down
66 changes: 66 additions & 0 deletions 66 lib/Extension/config/report/generators.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
<?php

$formatTime = function (string $expr) {
return sprintf(
<<<'EOT'
display_as_time(
%s,
coalesce(
row["time_unit"],
"time"
),
row["time_precision"],
row["time_mode"]
)
EOT
,
$expr
);
};

return [
'bare' => [
'generator' => 'bare',
Expand All @@ -21,6 +39,54 @@
'rstdev',
]
],
'aggregate-preview' => [
'title' => 'Aggregate by Subject',
'description' => "Aggregate results by subject and group by benchmark class.\nThis is a preview report and may change in minor version updates.",
'extends' => 'aggregate',
'break' => [
'benchmark',
],
'expressions' => [
'name' => sprintf(
'if(first(variant_name) != "", %s, %s)',
'first(subject_name) ~ " (" ~ first(variant_name) ~ ")"',
'first(subject_name)'
),
'_mode' => 'mode(result_time_avg)',
],
'cols' => [
'name',
'revs',
'its',
'mem_peak',
'mode',
'rstdev',
'diff',
],
'baseline_expressions' => [],
'derivations' => [
'diff' => sprintf(
'if(min(table["_mode"]) > 0, %s, %s)',
'format("%.2fx", row["_mode"] / min(table["_mode"]))',
'"N/A"'
),
'mode' => sprintf(
'if(row["baseline_exists"], %s, %s)',
$formatTime('row["_mode"]') . ' ~ " " ~ percent_diff(row["baseline_mode"], row["_mode"])',
$formatTime('row["_mode"]'),
),
'mem_peak' => sprintf(
'if(row["baseline_exists"], %s, %s)',
'(row["mem_peak"] as memory) ~ " " ~ percent_diff(row["baseline_mem_peak"], row["mem_peak"])',
'row["mem_peak"] as memory',
),
'rstdev' => sprintf(
'if(row["baseline_exists"], %s, %s)',
'(row["rstdev"] as "rstdev") ~ " " ~ percent_diff(row["baseline_rstdev"], row["rstdev"])',
'row["rstdev"] as "rstdev"',
),
]
],
'bar_chart_time' => [
'generator' => 'component',
'components' => [
Expand Down
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.