|
| 1 | +(ns example.perf |
| 2 | + (:require-macros [cljss.core]) |
| 3 | + (:require [cljss.core :as css :refer-macros [defstyles]] |
| 4 | + [rum.core :as rum] |
| 5 | + [goog.dom :as gdom])) |
| 6 | + |
| 7 | +(defstyles button [font-size] |
| 8 | + {:color "#fff" |
| 9 | + :background-color "rgb(0, 0, 255)" |
| 10 | + :border-radius "5px" |
| 11 | + :padding "8px 24px" |
| 12 | + :border "none" |
| 13 | + :font-size (str font-size "px") |
| 14 | + :&:hover {:background-color "rgb(0, 0, 230)" |
| 15 | + :font-size (str (* 1.2 font-size) "px")} |
| 16 | + "span" {:vertical-align "middle"}}) |
| 17 | + |
| 18 | +(println "compute defstyles") |
| 19 | +(simple-benchmark [] (button (js/Math.random)) 1000) |
| 20 | + |
| 21 | +(rum/defc NoStylesButton [] |
| 22 | + [:button {} "button"]) |
| 23 | + |
| 24 | +(rum/defc InlineButton [] |
| 25 | + (let [font-size (* 10 (js/Math.random))] |
| 26 | + [:button {:style {:color "#fff" |
| 27 | + :background-color "rgb(0, 0, 255)" |
| 28 | + :border-radius "5px" |
| 29 | + :padding "8px 24px" |
| 30 | + :border "none" |
| 31 | + :font-size (str font-size "px")}} |
| 32 | + "button"])) |
| 33 | + |
| 34 | +(rum/defc CSSAttrButton [] |
| 35 | + (let [font-size (* 10 (js/Math.random))] |
| 36 | + [:button {:css {:color "#fff" |
| 37 | + :background-color "rgb(0, 0, 255)" |
| 38 | + :border-radius "5px" |
| 39 | + :padding "8px 24px" |
| 40 | + :border "none" |
| 41 | + :font-size (str font-size "px")}} |
| 42 | + "button"])) |
| 43 | + |
| 44 | +(println "render NoStylesButton") |
| 45 | +(simple-benchmark [] (rum/mount (NoStylesButton) (gdom/getElement "NoStylesButton")) 1000) |
| 46 | + |
| 47 | +(println "render InlineButton") |
| 48 | +(simple-benchmark [] (rum/mount (InlineButton) (gdom/getElement "InlineButton")) 1000) |
| 49 | + |
| 50 | +(println "render CSSAttrButton") |
| 51 | +(simple-benchmark [] (rum/mount (CSSAttrButton) (gdom/getElement "CSSAttrButton")) 1000) |
0 commit comments