#lang scheme/base

(require scheme/future
         scheme/unsafe/ops
         scheme/fixnum)

(define (one-calculation)
  (display "calculatin'\n")
  (let loop ((i 0))
    (when (unsafe-fx< i 1000000000)
      (loop (unsafe-fx+ i 1)))))

(define (parallel)
  (define futures
    (for/list ([i (in-range 0 (processor-count))])
      (future one-calculation)))
  
  (for-each
   touch
   futures))

(define (serial)
  (for/list ((i (in-range 0 (processor-count))))
    (one-calculation)))

(define (main)
  (define start (current-milliseconds))
  (define after-parallel (begin (parallel) (current-milliseconds)))
  (define after-serial (begin (serial) (current-milliseconds)))
  
  (write (list start after-parallel after-serial))
  (newline)
  (write (list (- after-parallel start) (- after-serial after-parallel)))
  (newline))

(provide main)