toshsan / caliper

Automatically exported from code.google.com/p/caliper
Apache License 2.0
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by gak@google.com on 11 Apr 2013 at 11:28