Skip to content

Commit f416156

Browse files
committed
add perf demo
1 parent ed0f439 commit f416156

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Thease are some resources that can give you more context:
4848
- Nested CSS selectors
4949
- Injects styles into `<style>` tag at run-time
5050
- Debuggable styles in development (set via `goog.DEBUG`)
51-
- Fast, 10000 insertions in ~200ms
51+
- Fast, 1000 insertions in under 100ms
5252

5353
## How it works
5454

example/src/example/perf.cljs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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)

project.clj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,15 @@
5656
:closure-defines {"goog.DEBUG" false}
5757
:pseudo-names true
5858
:verbose true
59-
:pretty-print false}}]})
59+
:pretty-print false}}
60+
{:id "perf"
61+
:source-paths ["src" "example/src" "example/resources"]
62+
:compiler {:output-to "example/resources/public/js/compiled/perf.js"
63+
:output-dir "example/resources/public/js/compiled/out-perf"
64+
:main example.perf
65+
:optimizations :advanced
66+
:closure-defines {"goog.DEBUG" false}
67+
:static-fns true
68+
:fn-invoke-direct true
69+
:verbose true
70+
:pretty-print false}}]})

0 commit comments

Comments
 (0)