Improve performance of clojure.core/last
jfacorro opened this issue · comments
Juan Facorro commented
Compared to Clojure JVM, calling last
on a range
takes (at least) more than three times in Clojerl.
:clj | :clje | :runs | :time-clj | :time-clje | :ratio |
---|---|---|---|---|---|
[r (range 1000000)], (last r) | [r (range 1000000)], (last r) | 1 | 68 | 218 | 3.21 |
(Number take from here)
There is not clear indication of why this is the case. clojure.lang.Range
implements the IChunkedSeq
interface but that is not being used in the implementation of last
(see below).
(def
^{:arglists '([coll])
:doc "Return the last item in coll, in linear time"
:added "1.0"
:static true}
last (fn ^:static last [s]
(if (next s)
(recur (next s))
(first s))))
Even if last
did use this interface clojerl.Range
also implements the clojerl.IChunkedSeq
protocol.