-1
$\begingroup$

I am working on a algorithm for acoustic scattering in two dimensions using MatLab, and one of the advantages of this algorithm is that Hankel functions can be replaced with log functions.

For example consider the following:

  1. value = 0; tic; for t=1:100000, value = value + besselh(1,1,abs(1+1i)); end; toc
  2. value = 0; tic; for t=1:100000, value = value + log(abs(1+1i)); end; toc

1) takes about 1.095455 seconds, whereas 2) takes about 0.043890 seconds.

Coming from a mathematics background I'm used to analyzing numerical methods in cases such as determining the order of convergence of an ODE/PDE solver or a numerical integration method, along with judging complexity in a program by counting operations.

However in this case, the number of operations is the same (on the surface anyway). So how can the improvement in efficiency be classified in this case? Are empiric results, such as showing that 2) takes much less time than 1), the best I can do in this situation?

Or is there a more formal/rigorous way to classify the improved efficiency?

$\endgroup$
  • 1
    $\begingroup$ Right, the conclusion you can draw is that 1 is slower than 2, which is no surprise. There is nothing to be said about complexity, as there is no input size. An even less about efficiency. Lastly, you are comparing two different things. $\endgroup$ – Yves Daoust Apr 17 '17 at 16:31
  • 2
    $\begingroup$ 1) Has this anything to do with Matlab, specifically? Because then it's offtopic. 2) What's the cost of evaluating besselh vs log? Benchmark the two in isolation! $\endgroup$ – Raphael Apr 17 '17 at 17:08
  • $\begingroup$ @Raphael: hem, that's precisely what he did. $\endgroup$ – Yves Daoust Apr 17 '17 at 17:22
  • $\begingroup$ @Raphael No it's not Matlab in general, I would be interested in how they compare in other languages also, C/C++ in particular. $\endgroup$ – csss Apr 27 '17 at 7:15
3
$\begingroup$

Asymptotic analysis usually isn't useful, if you care about constant factors (such as a 20x speedup). Counting operations is useful if you only care about asymptotics and don't care about constant factors, but if different operations take a different amount of time and you care about constant factors, then counting operations may not be useful. Asymptotics are just a tool, but they're not always the right tool for every situation.

So, if you want to optimize at this level, you'll need to use different tools -- e.g., empirical evaluation, benchmarking on useful workloads, performance measurement, more precise models (instead of asymptotics).

$\endgroup$
  • 1
    $\begingroup$ Counting operations is still useful, provided you assign useful weights to the operations. Here, besselh (and probably log) are not operations but function calls; in order to analyse to the degree of precision we require, we need to unfold the declarations of these functions. $\endgroup$ – Raphael Apr 17 '17 at 19:53
  • $\begingroup$ @Raphael Yes it would be very interesting to know precisely what makes 'besselh' slower than 'log'. $\endgroup$ – csss Apr 27 '17 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.