Skip to content

Instantly share code, notes, and snippets.

@samdphillips
Created November 6, 2020 19:34
Show Gist options
  • Save samdphillips/7e9e285349ef6427f25b7fc9374ba269 to your computer and use it in GitHub Desktop.
Save samdphillips/7e9e285349ef6427f25b7fc9374ba269 to your computer and use it in GitHub Desktop.
#lang racket/base
#|
cpu time: 111 real time: 113 gc time: 0
cpu time: 141 real time: 142 gc time: 0
cpu time: 1125 real time: 1131 gc time: 4
|#
(module plain racket/base
(provide (struct-out st))
(struct st [x]))
(module contracted racket/base
(require racket/contract
(submod ".." plain))
(provide
(contract-out (struct st ([x integer?])))))
(require racket/match
'plain
(prefix-in c: 'contracted))
(define a (st 42))
(define b (c:st 42))
(collect-garbage)
(collect-garbage)
(collect-garbage)
(time
(for ([x 10000000])
(match a
[(? st?) 'ok])))
(collect-garbage)
(collect-garbage)
(collect-garbage)
(time
(for ([x 10000000])
(match a
[(st _) 'ok])))
(collect-garbage)
(collect-garbage)
(collect-garbage)
(time
(for ([x 10000000])
(match b
[(c:st _) 'ok])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment