octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

More on interpreter speed


From: Quentin Spencer
Subject: More on interpreter speed
Date: Wed, 04 Oct 2006 09:49:39 -0500
User-agent: Thunderbird 1.5.0.7 (X11/20060913)

This may be of interest to those who have recently expressed interest in finding ways of speeding up the interpreter. I was recently testing two different ways of computing the same vector inside a function to see which was fastest. My code was organized in the form:

tic
 block A
toc
tic
 block B
toc

where blocks A and B compute the same thing in different ways, but using some (not all) of the same intermediate variables. I was consistently getting results that looked like this:
Elapsed time is 0.025230 seconds.
Elapsed time is 0.001198 seconds.

Having assumed that computation B was faster, I replaced block A with a copy of what was in block B in the hope of further tweaking it. However, running the function with both of the blocks being identical, I noticed that I was still seeing the same large discrepancy in the times. I also tested the same thing in Matlab. The first time I ran it I got this:
Elapsed time is 0.003115 seconds.
Elapsed time is 0.000627 seconds.

All subsequent times I ran it, I got something more like this:
Elapsed time is 0.000481 seconds.
Elapsed time is 0.000433 seconds.

This was quite unexpected. I am used to getting faster results on the second run after a function has been loaded into memory, but this doesn't explain why octave consistently runs a block of code inside a function faster the second time than the first time. To me this looks like maybe octave is freeing the memory used for internal variables when it exits a function, and maybe Matlab is somehow holding onto it. Is my assessment correct? The most involved octave/matlab scripts I run usually involve many repeated calls to the same functions with similar parameters, so that keeping memory allocated for a subsequent call to the same function in this way would essentially gain me a 5x speedup in execution time. I'm sure this is fairly common among other users who do large computation as well. Assuming my guesses about what is going on here are correct, how difficult would it be to modify octave's approach to memory management? What possible negative consequences could result?

Quentin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]