Clojure

vec function is substantially slower than into function

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: Release 1.5
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
  • Approval:
    Incomplete

Description

(vec coll) and (into [] coll) do exactly the same thing. However, due to into using transients, it is substantially faster. On my machine:

(time (dotimes [_ 100] (vec (range 100000))))
"Elapsed time: 732.56 msecs"

(time (dotimes [_ 100] (into [] (range 100000))))
"Elapsed time: 491.411 msecs"

This is consistently repeatable.

Since vec's sole purpose is to transform collections into vectors, it should do so at the maximum speed available.

Activity

Luke VanderHart made changes -
Field Original Value New Value
Description {{(vec coll)}} and {{(into [] coll)}} do exactly the same thing. However, due to {{into}}s use of transients, it is substantially faster. On my machine:

(time (dotimes [_ 100] (vec (range 100000))))
"Elapsed time: 732.56 msecs"

(time (dotimes [_ 100] (into [] (range 100000))))
"Elapsed time: 491.411 msecs"

This is consistently repeatable.

Since {{vec}}'s sole purpose is to transform collections into vectors, it should do so at the maximum speed available.
{{(vec coll)}} and {{(into [] coll)}} do exactly the same thing. However, due to {{into}} using transients, it is substantially faster. On my machine:

(time (dotimes [_ 100] (vec (range 100000))))
"Elapsed time: 732.56 msecs"

(time (dotimes [_ 100] (into [] (range 100000))))
"Elapsed time: 491.411 msecs"

This is consistently repeatable.

Since {{vec}}'s sole purpose is to transform collections into vectors, it should do so at the maximum speed available.
Alex Miller made changes -
Labels performance
Alex Miller made changes -
Approval Triaged [ 10120 ]
Priority Trivial [ 5 ] Major [ 3 ]
Rich Hickey made changes -
Fix Version/s Release 1.7 [ 10250 ]
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Alex Miller made changes -
Issue Type Defect [ 1 ] Enhancement [ 4 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Incomplete [ 10006 ]
Alex Miller made changes -
Resolution Duplicate [ 3 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: