array-mult.glisp 636 B

1234567891011121314151617181920212223242526
  1. (defn mult-array-loop [a b res i]
  2. (cond (= i (len a)) res
  3. (begin
  4. (aset! res i (* (aget a i) (aget b i)))
  5. (mult-array-loop a b res (+ i 1)))))
  6. (defn mult-array [a b]
  7. (mult-array-loop a b (make-array (len a)) 0))
  8. (defn random-array [arr i]
  9. (cond (= i (len arr))
  10. arr
  11. (begin
  12. (aset! arr i (random))
  13. (random-array arr (+ i 1)))))
  14. (defn do-in-loop [func times]
  15. (cond (= times 0) '()
  16. (begin
  17. (func)
  18. (do-in-loop func (- times 1)))))
  19. (let [a (random-array (make-array 1000) 0)
  20. b (random-array (make-array 1000) 0)]
  21. (do-in-loop (fn [] (mult-array a b)) 1000))