Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reflection warnings and use Protocols for encoding/decoding #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

ducky427
Copy link

@ducky427 ducky427 commented Oct 20, 2017

With these changes, encode & decode is about 4 times faster.

I testes this code using criterium.

(use 'criterium.core)
(require '[clojure-erlastic.core :as c])

(def conf {:str-detect :none :convention :elixir :str-autodetect-len 10})

(def encode #(c/encode % conf))
(def decode #(c/decode % conf))

(defn f
  []
  (-> :toto encode decode)
  (-> {:a :b :c :d} encode decode)
  (-> [:a :b :c :d] encode decode)
  (-> '(:a :b :c :d) encode decode)
  (-> #{:a :b :c :d} encode decode)
  (-> 4.3 encode decode)
  (-> true encode decode)
  (-> (byte-array (repeat 4 0)) encode decode)
  (-> nil encode decode)
  (-> \c encode decode)
  (-> "toto" encode decode)
  nil)
(bench (f))

Before:

Evaluation count : 893640 in 60 samples of 14894 calls.
             Execution time mean : 72.383461 µs
    Execution time std-deviation : 5.949103 µs
   Execution time lower quantile : 65.927145 µs ( 2.5%)
   Execution time upper quantile : 83.833648 µs (97.5%)
                   Overhead used : 6.592387 ns

After:

Evaluation count : 3893340 in 60 samples of 64889 calls.
             Execution time mean : 15.769601 µs
    Execution time std-deviation : 394.241150 ns
   Execution time lower quantile : 15.214134 µs ( 2.5%)
   Execution time upper quantile : 16.606512 µs (97.5%)
                   Overhead used : 6.282802 ns

@ducky427 ducky427 changed the title Remove reflection warnings Remove reflection warnings and use Protocols Oct 21, 2017
@ducky427 ducky427 changed the title Remove reflection warnings and use Protocols Remove reflection warnings and use Protocols for encoding/decoding Oct 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant