Fork me on GitHub
#clojure
<
2022-09-01
>
Al Z. Heymer09:09:57

Shouldn't last be much faster on vectors? At least that is what I remembered to read. I did some basic benchmarking and fail to understand my results.

Al Z. Heymer09:09:33

user=> (def r (doall (range 1e+7)))
#'user/r
user=> (let [v (vec r)]
  #_=>   (time (last v))
  #_=>   (time (last r)))
"Elapsed time: 387.154079 msecs"
"Elapsed time: 157.53812 msecs"
9999999
user=> (let [v (vec r)]
  #_=>   (time (last r))
  #_=>   (time (last v)))
"Elapsed time: 277.38866 msecs"
"Elapsed time: 559.517154 msecs"
9999999

Al Z. Heymer09:09:52

I realized range, so that I really deal on the data instead of the realization. However, using last on a list seems to be way faster than on the preallocated vector . Does anyone have an explanation for that?

p-himik09:09:14

On the contrary - last doesn't check its argument's concrete type, so it traverses the whole structure. What's faster for vectors is peek.

👍 1
Al Z. Heymer09:09:50

Oh! So I misunderstood. Then why is it much slower to traverse the vector?

Alex Miller (Clojure team)13:09:38

Btw by using 1e+7 (a double) you get the nonoptimized version of range that works on longs

Alex Miller (Clojure team)13:09:43

you also want to run these many times to avoid jvm jit effects

quoll14:09:33

I’m expecting that the wild variations in time are due to the JVM effects. https://github.com/hugoduncan/criterium is ideal for this (documentation on the page)

escherize19:09:25

is there a way to “bake-in” a java argument when building an uberjar? I want to basically have java -jar mything.jar turn into java -jar -DsomeSetting=thing mything.jar. I tried setting the system property from the first clojure ns that gets loaded, but it behaves differently when I do that

Joshua Suskalo14:09:18

jdeploy also serves a bit of a different purpose as its output isn't a jar file, which may be a dealbreaker in some usecases.

Benjamin C20:09:26

Is there a way to see how much host interop a library with it's dependencies has?

Benjamin C20:09:28

Main motivation would be a rough estimate of how much work it would take to port to clojure/script/dart/clojurl/jank-lang etc.

Joshua Suskalo14:09:48

That feels like something you might be able to do with #clj-kondo analysis

Alex Miller (Clojure team)20:09:48

iff is an abbreviation used in math for “if and only if”

themoreyouknow 6
Alex Miller (Clojure team)20:09:03

that is its intent here

syd22:09:53

ah my bad sorry

Huahai21:09:57

For clojure.test.check generators, how to generate a bigint only, no longs?

respatialized21:09:34

Could you use gen/fmap to perform type conversion?

Huahai21:09:15

size-bounded-bigint generator seems to have this option, i just don’t know the syntax for it

Huahai21:09:15

i just want to know how to pass in force-bigint?

Huahai21:09:36

that example is the same as what I did, it generate both longs and bigints

skylize22:09:20

I think this should work for you.

(def gen-bigint (gen/such-that
                 #(= clojure.lang.BigInt (type %))
                 gen/size-bounded-bigint))

Huahai02:09:57

thx, will go with this for now