google / google/caliper

Feature Request: Support specifiable stack depth for trials to run at.

Open
#227 0 comments 0 reactions 0 assignees View on GitHub
P4 type=enhancement
Dominant language
Java
Stars
818
Forks
112
Avg merge
12m
Merged PRs (30d)
5

Description

```
Some code is very stack-depth dependent (anything that relies on allocating
exceptions or errors).
Being able to ask Caliper to run code at a certain stack depth (or even
execute several trials at different stack depths) would be very nice.

Currently I am mimicking this by forcing recursion inside the trial (but
outside the ultimate timing loop). The code is something like:

// Define the general trial interface
interface Trial {
T run(int reps);
}

static Trial createRecursiveTrial(final Trial trial, int depth) {
if (depth <= 0) {
return trial;
}
return new Trial() {
private final Trial delegate = createRecursiveTrial(trial, depth -1);
@Override T run(int reps) {
delegate.run(reps);
}
};
}

Then the timing loop is created in the setup() method as a Trial and wrapped to
add stack depth.

Of course this means that stack descent occurs during timing, though this
doesn't seem to make a noticeable difference but it would be nice if it could
occur before timing starts.

I have found no evidence that compilers are optimizing this away (*), but if we
thought it was a possibility, we could have more interesting ways to reach the
desired stack depth (e.g., define several classes that invoke each other in a
non-regular pattern).

* - The results I get with this technique are consistent with expectations and
show the expected linear relationship as regards allocating Throwable instances.
```

Original issue reported on code.google.com by `dbeaum...@google.com` on 28 Feb 2013 at 4:48

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.