タグ

2020年8月13日のブックマーク (3件)

  • GPソフト Wiki - ClojureでTransducer

    Transducer(xf)は、Reducing function用のTransformerである。 Transducerは関数合成可能。そして合成するとき、以下のことに依存しない。 入力コンテキスト(コレクションなのか、Streamなのか、Channelなのか?) 出力コンテキスト(コレクションが欲しいのか、スカラ値が欲しいのか?) こういったことは、最後にreduce/transduceするときまで気にする必要がない。 ;; コレクションからコレクションへ (transduce all-t conj d) ;;=> ["1" "2"] ;; スカラ値へ (transduce all-t str d) ;;=> "12" コンテキストを決めるのは、ここで使うconjやstrである。all-tが適切なrfを作ってくれる。このコードは、以下のコードと同じである。 (def rf-v (all

  • Clojure高速化テクニック - Qiita

    Clojureプログラムを高速化するためのテクニック集です。 稿に書いてある手法が全てではありません。個々の手法について細かく書いてはいないため、詳しい情報は他の文献を参照してください。また、Clojureプログラムの外側(JVMなど)については記述していません。 Premature optimization is the root of all evil. -- Donald Knuth 過度なチューニングは保守性や可読性を犠牲にする場合があるので、注意が必要です。 Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest. -- Rob Pike ボトルネックをきちんと調査した上で、適切なパフォーマンス

    Clojure高速化テクニック - Qiita
  • Clojure performance really bad on simple loop versus Java

    Spoiler alert, this is problem 5 of Project Euler. I am attempting to learn Clojure and solved problem 5, but it is a couple orders of magnitude slower (1515 ms in Java versus 169932 ms in Clojure). I even tried using type hinting, unchecked math operations, and inlining functions all for naught. Why is my Clojure code so much slower? Clojure code: (set! *unchecked-math* true) (defn divides? [^lon

    Clojure performance really bad on simple loop versus Java