From help-octave-request at bevo dot che dot wisc dot edu Fri Oct 31 11:56:40 2003 Subject: Re: Realtime cost of call by value From: taltman at lbl dot gov To: Glenn Golden cc: help-octave at bevo dot che dot wisc dot edu Date: Fri, 31 Oct 2003 09:55:21 -0800 (PST) Glenn & others, Thanks for all of *your* hard work! You took the initiative to get all of us to explore this facet of Octave, and then you even showed how it could be improved by three orders of magnitude! Just FYI, many high-level languages ( I'll use Scheme as an example ) don't EVER pass variables to functions via call-by-value, but call-by-reference. I'm talking about the interpreter, *not* the actual language. What this means, is that for any level of nested function calls, and for any number of arguments, there isn't a heavy performance penalty for large arguments. So even though it might look like you're just flat-out passing off a huge variable, internally only the scoped reference to that variable is being manipulated. What this kinda requires of the language, though, is some sort of formal bookkeeping of variable scope. It isn't that hard to implement a lexical scope. I'd recommend "The Structure and Interpretation of Computer Programs" for a good, clean explanation of how to achieve just this: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html Cheers, ~Tomer On Oct 30, 2003 at 9:47pm, Glenn Golden wrote: gdg >Date: Thu, 30 Oct 2003 21:47:32 -0700 gdg >From: Glenn Golden gdg >To: John W. Eaton gdg >Cc: help-octave at bevo dot che dot wisc dot edu gdg >Subject: Re: Realtime cost of call by value gdg >Resent-Date: Thu, 30 Oct 2003 22:47:34 -0600 gdg >Resent-From: help-octave at bevo dot che dot wisc dot edu gdg > gdg >"John W. Eaton" writes: gdg >> gdg >> On 30-Oct-2003, Glenn Golden wrote: gdg >> | virtual Matrix& matrix_reference (void) const gdg >> | { return rep->matrix_reference (); } gdg >> gdg >> The declaration of this function must match exactly the one in the gdg >> octave_matrix class. Probably it should not be const. gdg >> gdg > gdg >Ow. (And I was _missing_ a const from my earlier example... Maybe gdg >there's some sort of conservation law at work here...) gdg > gdg >Anyway... it's taken a little while, but it was well worth it: gdg > gdg > octave:4> ignore_function_time_stamp = "all" gdg > octave:5> global foo gdg > gdg > octave:6> foo = rand(1000); gdg > octave:7> poke; # DLD: Modify foo(1,1) via get/set_global_value() gdg > et = 21439.0 usec # (Dyn. load time is a negligible fraction of this.) gdg > gdg > gdg > octave:24> foo = rand(1000); gdg > octave:25> poke; # foo(1,1) mod via global_reference()/matrix_reference() gdg > et = 9.0 usec gdg > gdg >Just a sliiight three order of magnitude improvement. An extreme gdg >example perhaps, because of the size of the matrix, but even with gdg >the more modest dimensions in my problem, it will still make the gdg >difference between Octave being a feasible (and highly preferable) gdg >solution, vs. it being a non-starter, for speed reasons. I'm really gdg >happy about this. The fact that Octave can now be used to do this gdg >simulation is going to make it go a lot smoother, and probably faster gdg >to completion as well. It's a pleasure having a credible alternative gdg >to MathWorks. (And the help line is better too. :) gdg > gdg >So... Tomer, Geraint, and esp. John: Thanks, bigtime. The fact gdg >that this works is really going to make my life a lot easier over gdg >the next few weeks. gdg > gdg >In a few days, I'll post my 2 cents worth re John's poll question gdg >(about whether this capability become part of the distribution). gdg >Naturally, I think it should, but not just for the sake of my own gdg >application. I think the efficiency issue is larger than that, and gdg >I'd at least like to try to make the case that it's valuable enough gdg >to have it in the distro, even if it is hidden away and plastered gdg >with caveats. (And if the decision is made to do that, I will certainly gdg >be glad to help with integrating it in whatever way I can.) gdg > gdg >Thanks again for all your help, gdg > gdg >Glenn gdg > gdg > gdg > gdg >------------------------------------------------------------- gdg >Octave is freely available under the terms of the GNU GPL. gdg > gdg >Octave's home on the web: http://www.octave.org gdg >How to fund new projects: http://www.octave.org/funding.html gdg >Subscription information: http://www.octave.org/archive.html gdg >------------------------------------------------------------- gdg > gdg > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------