|
14 | 14 | ;; [clojure.test.check :as tc] |
15 | 15 | ;; [clojure.test.check.generators :as tc-gens] |
16 | 16 | ;; [clojure.test.check.properties :as tc-props] |
17 | | - [clojure.string :as str] |
| 17 | + [clojure.string :as str] |
| 18 | + [taoensso.encore :as enc] |
18 | 19 |
|
19 | 20 | ;; :cljs cannot compile taoensso.sente under :nodejs target |
20 | | - #?(:clj [taoensso.sente :as sente]))) |
| 21 | + #?(:clj [taoensso.sente :as sente]) |
| 22 | + |
| 23 | + [taoensso.sente.interfaces :as i] |
| 24 | + [taoensso.sente.packers.edn :as ep] |
| 25 | + [taoensso.sente.packers.transit :as tp] |
| 26 | + [taoensso.sente.packers.msgpack :as mp]) |
| 27 | + |
| 28 | + #?(:cljs |
| 29 | + (:require-macros |
| 30 | + [taoensso.sente-tests :refer [get-bench-data]]))) |
21 | 31 |
|
22 | 32 | (comment |
23 | 33 | (remove-ns 'taoensso.sente-tests) |
24 | 34 | (test/run-tests 'taoensso.sente-tests)) |
25 | 35 |
|
26 | 36 | ;;;; |
27 | 37 |
|
28 | | -#?(:clj (deftest _test-clj (is (= 1 1)))) |
29 | | -#?(:cljs (deftest _test-cljs (is (= 1 1)))) |
| 38 | +(defn get-bench-data [] |
| 39 | + #_{:a :A :b :B :c "foo", :v (vec (range 128)), :s (set (range 128))} |
| 40 | + {:ids (vec (repeatedly 1024 (fn [] (rand-int 32767)))) |
| 41 | + :data |
| 42 | + (vec |
| 43 | + (repeatedly 128 |
| 44 | + (fn [] |
| 45 | + {:children-types [(enc/uuid-str 8) (enc/uuid-str 8) (enc/uuid-str 8)] |
| 46 | + :description "" |
| 47 | + :tips nil |
| 48 | + :a-url-in-text nil |
| 49 | + :name (enc/uuid-str) |
| 50 | + :parents-ids nil |
| 51 | + :type-id 1 |
| 52 | + :experimental false |
| 53 | + :duration 61 |
| 54 | + :warnings nil |
| 55 | + :a-simple-string (enc/uuid-str 16) |
| 56 | + :a-double-number (rand 32767) |
| 57 | + :a-boolean-i-think-cant-recall nil |
| 58 | + :archive-date nil |
| 59 | + :another-number (rand-int 32767) |
| 60 | + :internal-notes nil |
| 61 | + :id (rand-int 32767) |
| 62 | + :a-boolean false |
| 63 | + :submit-date (str (enc/now-inst)) |
| 64 | + :display-name (enc/uuid-str) |
| 65 | + :user nil |
| 66 | + :a-vector-of-integers (vec (repeatedly 64 (fn [] (rand-int 128)))) |
| 67 | + :children-count (rand-int 1024) |
| 68 | + :a-usually-absent-string nil})))}) |
| 69 | + |
| 70 | +(defn packed-len [x] |
| 71 | + #?(:cljs (if (instance? js/Uint8Array x) (.-length x) (count x)) |
| 72 | + :clj (count x))) |
| 73 | + |
| 74 | +(defn bench1 [packer laps data] |
| 75 | + {:time (enc/qb laps (i/pack packer nil data (fn [x] (i/unpack packer nil (get x :value) (fn [y] (get y :value)))))) |
| 76 | + :size (packed-len (i/pack packer nil data (fn [x] (get x :value))))}) |
| 77 | + |
| 78 | +(deftest bench-packers |
| 79 | + (let [laps 1e2 |
| 80 | + bd (get-bench-data) |
| 81 | + ep (ep/get-packer) |
| 82 | + tp (tp/get-packer) |
| 83 | + mp (mp/get-packer)] |
| 84 | + |
| 85 | + (println "Benching comparison:" |
| 86 | + {:ep (bench1 ep laps bd) |
| 87 | + :tp (bench1 tp laps bd) |
| 88 | + :mp (bench1 mp laps bd)}))) |
30 | 89 |
|
31 | 90 | ;;;; |
32 | 91 |
|
|
0 commit comments