2018-03-11 12:33:02 +03:00
|
|
|
(load "Bench.carp")
|
|
|
|
(use Bench)
|
|
|
|
(Debug.sanitize-addresses)
|
|
|
|
|
|
|
|
(def a [0])
|
|
|
|
|
|
|
|
(defn some-swapping []
|
|
|
|
(let [b @&a]
|
2018-03-11 12:38:24 +03:00
|
|
|
(ignore (Array.swap b 0 1))))
|
2018-03-11 12:33:02 +03:00
|
|
|
|
|
|
|
(defn perform-bench [n]
|
|
|
|
(do
|
2018-05-20 10:57:51 +03:00
|
|
|
(println* "\nSwap with array length " n)
|
2018-03-11 12:33:02 +03:00
|
|
|
(set! a (Array.replicate n &1))
|
|
|
|
(bench some-swapping)))
|
|
|
|
|
2018-03-11 12:44:02 +03:00
|
|
|
(defn some-mutable-swapping []
|
|
|
|
(let [b @&a]
|
|
|
|
(ignore (Array.swap! &b 0 1))))
|
|
|
|
|
|
|
|
(defn perform-mutable-bench [n]
|
|
|
|
(do
|
2018-05-20 10:57:51 +03:00
|
|
|
(println* "\nMutable swap with array length " n)
|
2018-03-11 12:44:02 +03:00
|
|
|
(set! a (Array.replicate n &1))
|
|
|
|
(bench some-mutable-swapping)))
|
|
|
|
|
2018-03-11 12:33:02 +03:00
|
|
|
(defn main []
|
|
|
|
(do (perform-bench 1000)
|
|
|
|
(perform-bench 10000)
|
|
|
|
(perform-bench 100000)
|
2018-03-11 12:44:02 +03:00
|
|
|
(perform-bench 1000000)
|
|
|
|
(perform-mutable-bench 1000)
|
|
|
|
(perform-mutable-bench 10000)
|
|
|
|
(perform-mutable-bench 100000)
|
|
|
|
(perform-mutable-bench 1000000)))
|