(defn distance [[x0 y0 z0] [x1 y1 z1]]
(+ (Math/abs (- x0 x1))
(Math/abs (- y0 y1))
(Math/abs (- z0 z1))))
"Elapsed time: 9046.938164 msecs"
(defn distance [[x0 y0 z0] [x1 y1 z1]]
(+ (Math/abs ^long (- x0 x1))
(Math/abs ^long (- y0 y1))
(Math/abs ^long (- z0 z1))))
"Elapsed time: 291.773856 msecs"
:opieop:Yep, I've learned to turn on reflection warnings so I can fix ones in the critical path. I know CIDER will point them out when it's enabled, other tools might as well
I made the same discovery on the same function…
(defn distance [p1 p2] (reduce + (map #(Math/abs ^int (- %1 %2)) p1 p2)))
This was day25 where there’s a 4th dimensions and the numbers were low. I guess long is probably better in general, and spliting out the operations would also give a speed up
I learned this lesson with ^Character on day 5: https://github.com/thegeez/clj-advent-of-code-2018/blob/master/src/advent2018/core.clj#L389
was optimizing and cleaning up arjun
s 23-2 solution here and there:
https://github.com/arjun27/advent-of-code-clojure/blob/master/src/advent/2018/day23.clj
https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/2018/day23_2.clj
@norman you can (defn distance [^ints p1 ^ints p2]
there
@thegeez woah, you don't mess around with namespaces :kappa:
c++ guys are laughing at us :opieop:
Really?
I didn’t know ^ints was a thing, but it doesn’t help anything here
actually it is way slower, but primitive hint ^ints is for arrays of primitives
actually, ^ints
even throws execution a bit off, as it expects it to be arrays, so having ^int and ^ints at the same time ends up being slower than just ^ints
Performance wise? On peak performance on some of the exercises the JVM might be faster.