<div class="gmail_quote">On Fri, Jan 22, 2010 at 6:57 PM, Juan Jose Garcia-Ripoll <span dir="ltr"><<a href="mailto:juanjose.garciaripoll@googlemail.com">juanjose.garciaripoll@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im">This flexibility has a consequence, which is a small slowdown due to an addition memory read and comparison operations but I am sure the inline version will get much better.</div></div>
</blockquote><div><br></div><div>Inlining C code is not easy, but it is somehow working right now. The things are getting hairy enough that I had to ditch macros in favor of "static inline" C functions. This means the code may be faster or slower depending on what your compiler supports. However I am pretty confident that all GCC variants, MSVC and Sun's compiler do support "inline" in one form or another.</div>
<div><br></div><div>Now as for the figures. I am using the code below, stored in a single file, compiled and loaded. Due to the fact that everything is compiled in the same translation unit, we ony see the overheads of special variables, not of function calls, etc. BASE is the basic cost of the loops, FOO2 adds special variable bindings and FOO adds both binding and reading of special variables.</div>
<div><br></div><div>In the git/CVS version of ECL the results are as follows (Mac OS X 10.5, Leopard, gcc-4, no __thread attribute)</div><div> FOO</div><div>real time : 1.301 secs</div><div>run time  : 1.291 secs</div><div>
gc count  : 1 times</div><div>consed    : 128 bytes</div><div>FOO2</div><div>real time : 1.011 secs</div><div>run time  : 1.003 secs</div><div>gc count  : 1 times</div><div>consed    : 0 bytes</div><div>BASE</div><div>real time : 0.158 secs</div>
<div>run time  : 0.155 secs</div><div>gc count  : 1 times</div><div>consed    : 0 bytes</div><div><br></div><div>Using the new implementation of special variables</div><div><div>FOO</div><div>real time : 0.265 secs</div><div>
run time  : 0.263 secs</div><div>gc count  : 1 times</div><div>consed    : 224 bytes</div><div>FOO2</div><div>real time : 0.235 secs</div><div>run time  : 0.232 secs</div><div>gc count  : 1 times</div><div>consed    : 0 bytes</div>
<div>BASE</div><div>real time : 0.155 secs</div><div>run time  : 0.153 secs</div><div>gc count  : 1 times</div><div>consed    : 0 bytes</div><div><br></div><div>As expected, the overhead of reading a special variable is very small, about 30/10e6 ms, while variable binding is larger, 80ms, but way smaller than before.</div>
<div><br></div><div>I still have a couple problems to solve before promoting this code to CVS.</div><div><br></div><div>Juanjo </div></div><div><br></div><div>(declaim (optimize (speed 3) (safety 0)))</div><div><br></div>
<div>(defvar *a* 3)</div><div><br></div><div>(defun faa (x) x)</div><div><br></div><div>(defun foo (x)</div><div> (dotimes (i 10000000)</div><div>  (declare (fixnum i))</div><div>  (let ((*a* x)) (faa *a*))))</div><div><br>
</div><div><br></div><div>(defun foo2 (x)</div><div> (dotimes (i 10000000)</div><div>  (declare (fixnum i))</div><div>  (let ((*a* x)) (faa 2))))</div><div><br></div><div>(defun base (x)</div><div> (dotimes (i 10000000)</div>
<div>  (declare (fixnum i))</div><div>  (faa x)))</div><div><br></div><div>(ext:gc t)</div><div>(princ 'FOO)</div><div>(time (foo 1))</div><div>(princ 'FOO2)</div><div>(time (foo2 1))</div><div>(princ 'BASE)</div>
<div>(time (base 2))</div><div> </div></div><br><br clear="all"><br>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://juanjose.garciaripoll.googlepages.com">http://juanjose.garciaripoll.googlepages.com</a><br>