Fork me on GitHub
#adventofcode
<
2018-12-26
>
misha15:12:13

(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

fellshard16:12:22

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

misha17:12:15

@U06D9RGQM woah, you don't mess around with namespaces kappa

norman16:12:52

I made the same discovery on the same function…

norman16:12:16

(defn distance [p1 p2] (reduce + (map #(Math/abs ^int (- %1 %2)) p1 p2)))

norman16:12:04

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

misha16:12:01

@norman you can (defn distance [^ints p1 ^ints p2] there

norman17:12:10

I didn’t know ^ints was a thing, but it doesn’t help anything here

misha17:12:55

actually it is way slower, but primitive hint ^ints is for arrays of primitives

misha17:12:00

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

misha17:12:52

c++ guys are laughing at us opieop

gklijs18:12:58

Performance wise? On peak performance on some of the exercises the JVM might be faster.