array-mult.scm 698 B

123456789101112131415161718192021222324252627
  1. (define (mult-vector-loop a b res i)
  2. (if (= i (vector-length a)) res
  3. (begin
  4. (vector-set! res i (* (vector-ref a i) (vector-ref b i)))
  5. (mult-vector-loop a b res (+ i 1)))))
  6. (define (mult-vector a b)
  7. (mult-vector-loop a b (make-vector (vector-length a)) 0))
  8. (define (random-vector vec i)
  9. (if (= i (vector-length vec))
  10. vec
  11. (begin
  12. (vector-set! vec i (random 1.0))
  13. (random-vector vec (+ i 1)))))
  14. (define (do-in-loop func times)
  15. (if (= times 0) '()
  16. (begin
  17. (func)
  18. (do-in-loop func (- times 1)))))
  19. (let ((a (random-vector (make-vector 100) 0))
  20. (b (random-vector (make-vector 100) 0)))
  21. (do-in-loop (lambda () (mult-vector a b)) 200))