Skip to content

Instantly share code, notes, and snippets.

@mmurooka
Last active June 19, 2019 12:23
Show Gist options
  • Save mmurooka/63165b0e93941547c3bf075d5fa97c9a to your computer and use it in GitHub Desktop.
Save mmurooka/63165b0e93941547c3bf075d5fa97c9a to your computer and use it in GitHub Desktop.
Compare computation time between aux and let
(defun test1
(&aux a b c)
a
)
(defun test2
()
(let (a b c)
a
))
(defun test3
()
(let* (a b c)
a
))
(print "use aux")
(bench (dotimes (i 5000000) (test1)))
(print "use let")
(bench (dotimes (i 5000000) (test2)))
(print "use let*")
(bench (dotimes (i 5000000) (test3)))
$ roseus hoge.l
configuring by "/opt/ros/melodic/share/euslisp/jskeus/eus//lib/eusrt.l"
;; readmacro ;; object ;; packsym ;; common ;; constants ;; stream ;; string ;; loader ;; pprint ;; process ;; hashtab ;; array ;; mathtran ;; eusdebug ;; eusforeign ;; coordinates ;; tty ;; history ;; toplevel ;; trans ;; comp ;; builtins ;; par ;; intersection ;; geoclasses ;; geopack ;; geobody ;; primt ;; compose ;; polygon ;; viewing ;; viewport ;; viewsurface ;; hid ;; shadow ;; bodyrel ;; dda ;; helpsub ;; eushelp ;; xforeign ;; Xdecl ;; Xgraphics ;; Xcolor ;; Xeus ;; Xevent ;; Xpanel ;; Xitem ;; Xtext ;; Xmenu ;; Xscroll ;; Xcanvas ;; Xtop ;; Xapplwin
connected to Xserver DISPLAY=:0
X events are being asynchronously monitored.
;; pixword ;; RGBHLS ;; convolve ;; piximage ;; pbmfile ;; image_correlation ;; oglforeign ;; gldecl ;; glconst ;; glforeign ;; gluconst ;; gluforeign ;; glxconst ;; glxforeign ;; eglforeign ;; eglfunc ;; glutil ;; gltexture ;; glprim ;; gleus ;; glview ;; toiv-undefined ;; fstringdouble irtmath irtutil irtc irtgeoc irtgraph ___time ___pgsql irtgeo euspqp pqp irtscene irtmodel irtdyna irtrobot irtsensor irtbvh irtcollada irtpointcloud irtx eusjpeg euspng png irtimage irtglrgb
;; extending gcstack 0x55ff1ed1b690[16374] --> 0x55ff1f1a0b70[32748] top=3d61
irtgl irtglc irtviewer
EusLisp 9.26( 1.2.1) for Linux64 created on ip-172-30-1-203(Fri May 31 16:58:14 PST 2019)
roseus ;; loading roseus("1.7.4") on euslisp((9.26 ip-172-30-1-203 Fri May 31 16:58:14 PST 2019 1.2.1))
eustf roseus_c_util
"use aux"
;; time -> 0.738809[s]
"use let"
;; time -> 0.889221[s]
"use let*"
;; time -> 0.842709[s]
@Affonso-Gui
Copy link

Affonso-Gui commented Jun 19, 2019

I performed some tests in my environment and got the same results. &aux faster than let* faster than let. Actually was also surprised that sequential let is faster than the parallel one.

The &aux bind is:

    while (iscons(formal)) {
      fvar=ccar(formal); formal=ccdr(formal);
      if (iscons(fvar)) {
        initform=ccdr(fvar);
        fvar=ccar(fvar);
        if (iscons(initform)) {GC_POINT;aval=eval(ctx,ccar(initform));}
        else aval=NIL;}
      else aval=NIL;
      env=vbind(ctx,fvar,aval,env,bf); }

and the let* bind is:

  while (islist(vlist)) {
    GC_POINT;
    var=ccar(vlist); vlist=ccdr(vlist);
    if (islist(var)) {
      init=ccdr(var); var=ccar(var);
      if (islist(init)) init=eval(ctx,ccar(init));
      else init=NIL;}
    else init=NIL;
    env=vbind(ctx,var,init,env,bf);
    }

Not much difference in here, so the time delay is probably due to the calling of the eus function.

Overall I would say that &aux is good for optimization, and let for readability.
Thanks for the discussion.

@mmurooka
Copy link
Author

What does sequential let is faster than the sequential one mean?

@Affonso-Gui
Copy link

Sorry, fixed that typo on the above comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment