Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

I like it using newLISP :)

  ;calculate primes in a range
  (define (primes from to)
    (local (plist)
        (for (i from to)
            (if (= 1 (length (factor i)))
                (push i plist -1)))
        plist))

  (set 'start (time-of-day))

  ; start child processes
  (spawn 'p1 (primes 1 1000000))
  (spawn 'p2 (primes 1000001 2000000))
  (spawn 'p3 (primes 2000001 3000000))
  (spawn 'p4 (primes 3000001 4000000))

  ; wait for a maximum of 60 seconds for all tasks to finish
  ; returns true if all finished in time
  (sync 60000) 

  ; p1, p2, p3 and p4 now each contain a lists of primes
  (println "time spawn: " (- (time-of-day) start))
  (println "time simple: " (time  (primes 1 4000000)))

  (exit)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: