KC
вот тут еще советую почитать про альтернативную имплементацию
Size: a a a
KC
KC
AC
AC
KC
(time
(dotimes [i 1000000]
(conj [] i)))
;; "Elapsed time: 70.439744 msecs"
(time
(dotimes [i 1000000]
(.add (java.util.ArrayList.) i)))
;; "Elapsed time: 48.26328 msecs"
RS
(time
(dotimes [i 1000000]
(conj [] i)))
;; "Elapsed time: 70.439744 msecs"
(time
(dotimes [i 1000000]
(.add (java.util.ArrayList.) i)))
;; "Elapsed time: 48.26328 msecs"
KC
RS
RS
(time (dotimes [i 1000000] (conj [] i)))
"Elapsed time: 38.424023 msecs"
nil
(time (dotimes [i 1000000] (.add (java.util.ArrayList.) i)))
"Elapsed time: 24.367542 msecs"
nil
(time (dotimes [i 1000000] (conj [] i)))
"Elapsed time: 21.485425 msecs"
nil
(time (dotimes [i 1000000] (conj [] i)))
"Elapsed time: 21.172863 msecs"
nil
(time (dotimes [i 1000000] (.add (java.util.ArrayList.) i)))
"Elapsed time: 41.148749 msecs"
nil
(time (dotimes [i 1000000] (.add (java.util.ArrayList.) i)))
"Elapsed time: 32.972849 msecs"
KC
ST
(conj [] "") #_"20 ns"
(.add (java.util.ArrayList.) "") #_"12 ns"
AC
(time
(dotimes [i 1000000]
(conj [] i)))
;; "Elapsed time: 70.439744 msecs"
(time
(dotimes [i 1000000]
(.add (java.util.ArrayList.) i)))
;; "Elapsed time: 48.26328 msecs"
KC
Of course, your mileage will vary, but it’s definitely not 20-50x slower, and you shouldn’t have to worry about its performance when starting on a project1. The persistent vector also has a very low memory overhead, only slightly higher than the average memory overhead of an ArrayList.
KC
ИИ
AC
KC
Of course, your mileage will vary, but it’s definitely not 20-50x slower
`AC
AC
AC