Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think that's inconceivable at all. You have an application where the "payload" is fairly minuscule (though that of course depends on the value of <code>n</code>), and you have to accept that the extra effort required (to connect the profiler and shift all the information across to it) will swamp that payload.</p> <p>This is not the sort of application I would be profiling in the first place since it's pretty obvious that the vast amount of time would be spent in <code>fib</code> anyway (for non-trivial values of <code>n</code>), marking that as an obvious target for optimisation.</p> <p>I would be more inclined to use the profiler for more substantial applications where:</p> <ul> <li>it's not obvious where the optimisation effort should go; and</li> <li>there is some substantial amount of work to do in the payload.</li> </ul> <p>If you really want to test <em>that</em> code, you probably need to bump up its effect by (for example) replacing:</p> <pre><code>int fib = fib(n); </code></pre> <p>with:</p> <pre><code>for (int i = 0; i &lt; 100000; i++) { int fib = fib(n); ) </code></pre> <hr> <p>I'll tell you <em>one</em> thing to watch out for though. I don't know the internals of any particular JVM but using a recursive method where the reduction of the argument is slow is usually a bad idea, one that leads to stack space being exhausted pretty quickly.</p> <p>By that, I mean a binary search is a good candidate since it removes half the remaining search space with each recursion level (so that a search space of a billion items is only 30 levels).</p> <p>On the other hand, using recursion for a Fibonacci sequence on the number 1,000,000,000 would take about a billion levels and most stacks would have a hard time containing that.</p> <p>Tail end recursion optimisation may avoid that problem but you need to be careful in case that optimisation isn't done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload