strange performance behavior of mem-aref
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
CFFI |
Won't Fix
|
Wishlist
|
Unassigned |
Bug Description
I'm using CFFI from quicklisp whose version seems 0.20.0 and SBCL 1.5.3. The system is Linux version 4.19.49-1-MANJARO.
In my computer the following code consumes about 0.5 seconds
-------
(defparameter data (foreign-alloc :double :count 1000000))
(defparameter dtype :double)
(time (loop for i from 0 below 1000000
do (mem-aref data dtype i))) ; fixed as per comment #1
Evaluation took:
2.434 seconds of real time
0.005647 seconds of total run time (0.005329 user, 0.000318 system)
0.25% CPU
3 forms interpreted
6,063,810,392 processor cycles
4 page faults
1,162,272 bytes consed
-------
However, if replace dtype by :double directly then the time consumed is just 0.002 seconds. It is almost 250 times faster
-------
(time (loop for i from 0 below 1000000
do (mem-aref data :double i)))
Evaluation took:
0.002 seconds of real time
0.002469 seconds of total run time (0.002190 user, 0.000279 system)
100.00% CPU
6,150,333 processor cycles
0 bytes consed
-------
I don't if it is a bug or feature. It greatly affects the efficiency of accessing the slots of object built upon CFFI anyway.
description: | updated |
Sorry, the first part of code is pasted wrong, it is ------- ------- ------- ------- ------- ------- ------- ---- ------- ------- ------- ------- ------- ------- ------- ----
-------
(time (loop for i from 0 below 1000000
do (mem-aref data dtype i)))
Evaluation took:
0.447 seconds of real time
0.445206 seconds of total run time (0.445087 user, 0.000119 system)
[ Run times consist of 0.019 seconds GC time, and 0.427 seconds non-GC time. ]
99.55% CPU
1,112,480,384 processor cycles
143,980,224 bytes consed
-------