Carp/bench/map.carp
Veit Heller 5ad1d227f3
Add automatic map resizing (#1071)
* core: add map resizing

* add set resizing

* do not shrink if under dflt-size
2020-12-19 22:20:52 +01:00

86 lines
1.6 KiB
Plaintext

(load "Bench.carp")
(use-all Bench IO)
(defn insert []
(let [m {}]
(for [i 0 100]
(Map.put! &m &i &1))))
(defn insert-collisions []
(let [m {}]
(for [i 0 100]
(Map.put! &m &1 &1))))
(def m (the (Map Int Int) {}))
(defn single-insert []
(Map.put! &m &1 &1))
(defn setup-big-map []
(for [i 0 10000]
(Map.put! &m &i &1)))
(defn retrieve []
(Map.get &m &10))
(defn map-tests []
(do
(println "Testing single map insert:")
(bench single-insert)
(println "")
(println "Testing 100 map inserts:")
(bench insert)
(println "")
(println "Testing 100 map inserts with maximum collisions:")
(bench insert-collisions)
(println "")
(setup-big-map)
(println "Testing map retrieval:")
(bench retrieve)
(println "")))
(defn insert-set []
(let [m (Set.create)]
(for [i 0 100]
(Set.put! &m &i))))
(defn insert-set-collisions []
(let [m (Set.create)]
(for [i 0 100]
(Set.put! &m &i))))
(def s (the (Set Int) (Set.create)))
(defn single-insert-set []
(Set.put! &s &1))
(defn setup-big-set []
(for [i 0 10000]
(Set.put! &s &i)))
(defn contains-set []
(Set.contains? &s &10))
(defn set-tests []
(do
(println "Testing single set insert:")
(bench single-insert-set)
(println "")
(println "Testing 100 set inserts:")
(bench insert-set)
(println "")
(println "Testing 100 set inserts with maximum collisions:")
(bench insert-set-collisions)
(println "")
(setup-big-set)
(println "Testing set contains:")
(bench contains-set)
(println "")))
(defn main []
(do
(map-tests)
(println "")
(set-tests)))