Created
July 16, 2014 18:30
-
-
Save bryanwoods/5314d84c77992d5428f2 to your computer and use it in GitHub Desktop.
Trying to benchmark an iterative vs recursive solution in Racket Scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define min 0) | |
(define max 100000000) | |
(define (recursive-function n) | |
(if (>= n max) | |
n | |
(recursive-function (+ n 1)))) | |
(define (iterative-function n) | |
(let loop () | |
(set! n (+ n 1)) | |
(when (< n max) (loop))) | |
n) | |
(pretty-display "Benchmarking the recursive function...") | |
(time (recursive-function min)) | |
(pretty-display "Benchmarking the iterative function...") | |
(time (iterative-function min)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmarking the recursive function... | |
cpu time: 7778 real time: 7778 gc time: 0 | |
100000000 | |
Benchmarking the iterative function... | |
cpu time: 12079 real time: 12072 gc time: 0 | |
100000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment