bench: add structs benchmark

This commit is contained in:
hellerve 2018-01-25 17:37:30 +01:00
parent 9a3b0e5f59
commit b3b64d9cd9

22
bench/structs.carp Normal file
View File

@ -0,0 +1,22 @@
(load "Bench.carp")
(use Bench)
(deftype Point [x Int, y Int])
(def p (Point.init 0 0))
(defn creation [] (Point.init 0 0))
(defn access [] (Point.x &p))
(defn set [] (Point.set-x @&p 5))
(defn update [] (Point.update-x @&p Int.inc))
(defn main []
(do
(IO.println "Struct creation:")
(bench creation)
(IO.println "\nStruct access:")
(bench access)
(IO.println "\nUpdate lens:")
(bench update)
(IO.println "\nSetter lens:")
(bench set)))