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> {
T run(int reps);
}
static <T> Trial<T> createRecursiveTrial(final Trial<T> trial, int depth) {
if (depth <= 0) {
return trial;
}
return new Trial<T>() {
private final Trial<T> 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
Original issue reported on code.google.com by
dbeaum...@google.com
on 28 Feb 2013 at 4:48