Interesting. This is the timing on Mac. Comparing to Alex's result,
the numbers roughly match "< 7s" v.s. "> 13s" while fact-1 is close.
$ racket
Welcome to Racket v7.2.0.3.
> (enter! "factorial.rkt")
"factorial.rkt"> (equal? (fact 10) (fact-1 10))
#t
"factorial.rkt"> (time (void (fact-1 1
You can check if the big number multiplication is the problem, by using a
factorial version which does not need so many big number multiplications:
#lang racket/base
(require racket/math)
(define (fact n)
(if (zero? n) 1 (* n (fact (- n 1)
(define (fact-1 n)
(define nslots (exact-truncat
On 3/24/2019 1:20 PM, Phil Nguyen wrote:
With Racket 7.2, the following program takes >13 seconds to run on
Windows, and <7 seconds on Linux either on Virtualbox on the same
machine, or native Linux on another machine with slightly
lower-powered processor:
|
#lang racket/base(define (fact n)
With Racket 7.2, the following program takes >13 seconds to run on Windows,
and <7 seconds on Linux either on Virtualbox on the same machine, or native
Linux on another machine with slightly lower-powered processor:
#lang racket/base
(define (fact n)
(if (zero? n) 1 (* n (fact (- n 1)
(tim
4 matches
Mail list logo