mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
36 lines
809 B
Plaintext
36 lines
809 B
Plaintext
(load "Bench.carp")
|
|
(use Bench)
|
|
(Debug.sanitize-addresses)
|
|
|
|
(def a [0])
|
|
|
|
(defn some-swapping []
|
|
(let [b @&a]
|
|
(ignore (Array.swap b 0 1))))
|
|
|
|
(defn perform-bench [n]
|
|
(do
|
|
(println* "\nSwap with array length " n)
|
|
(set! a (Array.replicate n &1))
|
|
(bench some-swapping)))
|
|
|
|
(defn some-mutable-swapping []
|
|
(let [b @&a]
|
|
(ignore (Array.swap! &b 0 1))))
|
|
|
|
(defn perform-mutable-bench [n]
|
|
(do
|
|
(println* "\nMutable swap with array length " n)
|
|
(set! a (Array.replicate n &1))
|
|
(bench some-mutable-swapping)))
|
|
|
|
(defn main []
|
|
(do (perform-bench 1000)
|
|
(perform-bench 10000)
|
|
(perform-bench 100000)
|
|
(perform-bench 1000000)
|
|
(perform-mutable-bench 1000)
|
|
(perform-mutable-bench 10000)
|
|
(perform-mutable-bench 100000)
|
|
(perform-mutable-bench 1000000)))
|