Skip to content

Instantly share code, notes, and snippets.

@samth
Created October 6, 2019 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samth/72e80e42dc1d799b59221577ec008c3c to your computer and use it in GitHub Desktop.
Save samth/72e80e42dc1d799b59221577ec008c3c to your computer and use it in GitHub Desktop.
#lang racket/base
(require racket/future)
(define N 100000000)
(define v (for/vector #:length N ([i N]) i))
(define (sum-vec v)
(for/sum ([i (in-vector v)]) i))
;(time (+ (sum-vec v) (sum-vec v)))
(define t1 (current-process-milliseconds))
(time (let ([n1 (future (lambda () (sum-vec v)))]
[n2 (sum-vec v)])
(+ (touch n1) n2)))
(define t2 (current-process-milliseconds))
(- t2 t1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment