Optimized 'Array.subarray', 3.90575s -> 25.046ms for taking the first half of an array of 10k ints.

This commit is contained in:
Erik Svedäng 2018-03-11 14:30:38 +01:00
parent ef6c7ac620
commit a83d343a98
4 changed files with 28 additions and 3 deletions

26
bench/array_subarray.carp Normal file
View File

@ -0,0 +1,26 @@
(load "Bench.carp")
(use Bench)
(load "Debug.carp")
(Debug.sanitize-addresses)
(use Array)
(def n 1000)
(defn some-subarray []
(let-do [a (replicate n &1)
b (subarray &a 0 (/ n 2))]
(assert (= (/ n 2) (count &b)))))
(defn perform-bench [new-n]
(do
(set! n new-n)
(println* "\nTaking sub-array of array with count " n)
(bench some-subarray)))
(defn main []
(do
(perform-bench 1000)
(perform-bench 10000)
(perform-bench 100000)
))

View File

@ -17,8 +17,8 @@
(defn perform-bench [new-n]
(do
(println* "\nUpdating array with count " n)
(set! n new-n)
(println* "\nUpdating array with count " n)
(bench some-updating)))
(defn main []

View File

@ -53,7 +53,7 @@
(let [result []]
(do
(for [i start-index end-index]
(set! result (push-back @&result @(nth xs i))))
(set! result (push-back result @(nth xs i))))
result)))
(defn prefix-array [xs end-index]

View File

@ -34,7 +34,6 @@
* [0.4] The type error when setting a variable but missing the '&' is confusing: "Can't unify Int with &Int"
* [0.4] Defining a function like 'add-ref' (see the numeric modules), refering to '+' does not resolve to '+' inside the module, which gives the function an overly generic type.
* [0.4] Report correct column in errors at all times, sometimes it's a bit too low.
* [0.4] Split up core into smaller modules.
* [1.0] Macros for generating 'read' functions to read objects back into memory from string representation.
* [1.0] A way to assert compiler errors in tests