Fork me on GitHub
#data-science
<
2015-10-30
>
aaelony16:10:19

A friend of mine wanted to compare benchmark times for summing a 1e9 collection of ones, between R and Clojure, just for fun. In R, it is

x <- rep(1,1e9)
system.time( { s<- sum(x) })
R: 1.278 user, 0 system 1.279 elapsed
roughly. The best clojure equivalent I came up with so far was
(require '[hiphip.int :as hiphip]) 
(def x (let [v (vec (range 1e9))] (hiphip/amake [i 1e9] 1)))

user=> (time (hiphip/asum x))
"Elapsed time: 2854.957051 msecs"
1000000000
but perhaps someone knows an even better way. Would core.matrix be faster? We realize of course that benchmarks are often silly, but in the spirit of fun, can we think up a better way?

squest16:10:10

I’m not familiar with R, are those numbers in ms?

mikera18:10:37

with core.matrix:

mikera18:10:39

(set-current-implementation :vectorz)

mikera18:10:50

(def x (broadcast (scalar-array 1) [1e9]))

mikera18:10:47

(time (esum x)) "Elapsed time: 0.08469 msecs"

aaelony18:10:03

holy crap! that's awesome, @mikera !!

aaelony18:10:49

nice syntax too

mikera18:10:53

Well.... it's a bit of a silly benchmark. Vectorz is smart enough to spot that it can optimise the broadcast to a specialised representation

aaelony18:10:26

understood, benchmarks are indeed silly

aaelony20:10:25

@mikera, is dantzig's simplex algorithm available in core.matrix?