zelark / nano-id

A unique string ID generator for Clojure and ClojureScript (・_・)ノ
MIT License
191 stars 9 forks source link

Small readability improvement #3

Closed zarkone closed 6 years ago

zarkone commented 6 years ago

Looking at definition of str at clojure.core, I think this version of core/nano-id implementation is totally equivalent, but a little bit more readable and easier to maintain. But it's just my opinion, no pushing :)

zelark commented 6 years ago

Yeah, it looks nice and neat, but the performance is lower.

On my mac, for 300000 runs, I get ~3000 msecs with your solution and ~2000 with the original one.

(with-out-str (time (dotimes [_ 300000] (nano-id.core/nano-id))))
"\"Elapsed time: 3082.928719 msecs\"\n"
user=> (with-out-str (time (dotimes [_ 300000] (nano-id.core/nano-id))))
"\"Elapsed time: 3334.916919 msecs\"\n"
user=> (with-out-str (time (dotimes [_ 300000] (nano-id.core/nano-id))))
"\"Elapsed time: 2823.433563 msecs\"\n"
user=> (with-out-str (time (dotimes [_ 300000] (nano-id.core/nano-id))))
"\"Elapsed time: 1973.260103 msecs\"\n"
user=> (with-out-str (time (dotimes [_ 300000] (nano-id.core/nano-id))))
"\"Elapsed time: 1933.902395 msecs\"\n"
user=> (with-out-str (time (dotimes [_ 300000] (nano-id.core/nano-id))))
"\"Elapsed time: 1874.54506 msecs\"\n"
zarkone commented 6 years ago

Got it, makes sense! Nevermind then, sorry for disturbing :)

zelark commented 6 years ago

No problem, man. (: