d1b8d03604
This commit updates the benchmark and repeat counts for various example files. These changes reflect potential performance improvements or variations observed during testing.
50 lines
1.4 KiB
Plaintext
50 lines
1.4 KiB
Plaintext
;; Benchmark: 1.2us
|
|
;; Benchmark-Repeat: 1634
|
|
;; Output: ["Alice" 101 :admin "Zürich" ["Alice" "Bob"] true]
|
|
|
|
; ---------------------------------------------------------
|
|
; Records & Optimized Field Access Showcase
|
|
; ---------------------------------------------------------
|
|
|
|
(do
|
|
; 1. Record Creation
|
|
; Records use interned layouts for O(1) access and low memory overhead.
|
|
(def user {:id 101 :name "Alice" :role :admin})
|
|
|
|
; 2. Optimized Field Access
|
|
; These calls are transformed by the optimizer into specialized instructions.
|
|
(def name (.name user))
|
|
(def id (.id user))
|
|
|
|
; 3. First-Class Field Accessors
|
|
; Accessors start with a dot and can be passed around like functions.
|
|
(def get-role .role)
|
|
(def role (get-role user))
|
|
|
|
; 4. Nested Records
|
|
(def company {
|
|
:name "Myc Corp"
|
|
:location {:city "Zürich" :zip 8000}
|
|
:employees [user {:id 102 :name "Bob" :role :dev}]
|
|
})
|
|
|
|
; Deep access (also optimized)
|
|
(def city (.city (.location company)))
|
|
|
|
; 5. Higher-Order usage
|
|
; Accessors are perfect for mapping over data.
|
|
(def names ((fn [f list]
|
|
(do
|
|
(def [e1 e2] list)
|
|
[(f e1) (f e2)]
|
|
))
|
|
.name (.employees company)))
|
|
|
|
; 6. Structural Identity
|
|
; Records with the same layout share memory; equality checks values.
|
|
(def is-equal (= {:x 1 :y 2} {:x 1 :y 2}))
|
|
|
|
; Return a summary of all tested features
|
|
[name id role city names is-equal]
|
|
)
|