https://github.com/magnusmorton/trace-analysis
Raw File
Tip revision: 4645af99638edea16d00e811c922b0fb9d6b86d9 authored by Magnus Morton on 11 January 2016, 20:33:10 UTC
subplots and recording output
Tip revision: 4645af9
bubble.rkt
#lang pycket
;; The Bubble sort benchmark from Strickland et al 2012
(define SIZE (string->number (vector-ref (current-command-line-arguments) 0 )))

(define vec (make-vector SIZE))

(define (bubble-sort vec)
  (define SIZE-1 (- SIZE 1))
  (if (time (let loop ([swapped? #f] [i 0])
        (if (= i SIZE-1)
            swapped?
            (let ([a (vector-ref vec i)]
                  [b (vector-ref vec (+ 1 i))])
              (if (> a b)
                  (begin
                    (vector-set! vec i b)
                    (vector-set! vec (+ 1 i) a)
                    (loop #t (+ i 1)))
                  (loop swapped? (+ 1 i)))))))
      (bubble-sort vec)
      #f))
(let loop ([i 0])
  (if (< i SIZE)
      (begin
        (vector-set! vec i (- SIZE i))
        (loop (+ 1 i)))
      #f))

(time (bubble-sort vec))
;(bubble-sort vec)
back to top