|
Re: Please try out FFI speed improvement: msg#00052lisp.clisp.general
Hoehle, Joerg-Cyril writes: > Aurelio Bignoli wrote: > >with-c-var/cast > > Real time: 1.273894 sec. (it was 1.494392) > >with-foreign-object/%cast > > Real time: 0.521461 sec. (it was 0.638666) > > This is strange, since the compiler macro using LOAD-TIME-VALUE is > supposed to do exactly what I did by hand using %CAST > directly. Therefore, one should not see any difference in speed (or > slowness). You are right. For my tests I used the following two functions: (defun get-foreign-data-2 (data size type) (with-c-var (p 'c-pointer data) (cast p (cond ((eq type 'integer) '(c-ptr int)) ((eq type 'string) `(c-ptr (c-array character ,size))) (t (multiple-value-bind (ft byte-size) (foreign-element-type type) `(c-ptr (c-array ,ft ,(/ size byte-size))))))))) (defun get-foreign-data-3 (data size type) (declare (ignore size)) (cond ((eq type 'integer) (with-foreign-object (p 'c-pointer data) (ffi::foreign-value (ffi::%cast p (load-time-value (ffi::parse-c-type '(c-ptr int))))))) ((eq type 'string) "") (t 0))) In both cases the COND macro expands into (IF (EQ TYPE 'INTEGER) ...) so, in my opinion, the execution time of the two functions should be equivalent to the execution time of WITH-C-VAR or WITH-FOREIGN-OBJECT plus the execution time of IF. I was wrong: the following, simpler functions: (defun get-foreign-int-1 (data) (with-c-var (p 'c-pointer data) (cast p '(c-ptr int)))) (defun get-foreign-int-2 (data) (with-foreign-object (p 'c-pointer data) (ffi::foreign-value (ffi::%cast p (load-time-value (ffi::parse-c-type '(c-ptr int))))))) have exactly the same execution time. ------------------------------------------------------- This SF.net email is sponsored by: ValueWeb: Dedicated Hosting for just $79/mo with 500 GB of bandwidth! No other company gives more support or power for your dedicated server http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Refinance your Home Today!: 00052, marketing4u |
|---|---|
| Next by Date: | FFI: :malloc-free allocation (was: FFI guru/wizard award to be re warded): 00052, Aurelio Bignoli |
| Previous by Thread: | Re: Please try out FFI speed improvementi: 00052, Hoehle, Joerg-Cyril |
| Next by Thread: | (±¤°í)¾Æ´Ï! ÀÌ ¹«½¼ ³¿»õ......???@: 00052, ½Å¿ë ö |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |