[racket] #lang racket vs. racket/base
At Wed, 12 Feb 2014 06:02:30 +0100, Manfred Lotz wrote:
> I just read Neil van Dyke's statement:
>
> < "#lang racket" is for demos, IMHO; I *always* use "#lang racket/base"
> < for any code that's not a demo.
>
> Question: What are the advantages of doing requires explicitly?
>
> In a program of mine I changed #lang racket to #lang racket/base and
> added:
>
> (require racket/cmdline)
> (require racket/string)
> (require racket/format)
> (require racket/port)
> (require racket/path)
> (require racket/list)
>
>
> The resulting executable (created by raco exe...) had the same size.
I'm surprised that they were the same size, assuming that you didn't
import other libraries that have more dependencies.
With these two files:
r.rkt
-----
#lang racket
b.rkt
-----
#lang racket/base
(require racket/cmdline
racket/string
racket/format
racket/port
racket/path
racket/list)
on my machine, `raco exe b.rkt` produces a 2.4 MB executable, while
`raco exe r.rkt` produces a 5.2MB executable.
There's a similarly significant difference in startup times for me:
laptop% time racket -l racket/base
0.030u 0.013s 0:00.04 100.0% 0+0k 0+0io 0pf+0w
laptop% time racket -l racket/base -l racket/string -l racket/cmdline \
-l racket/format -l racket/port -l racket/path -l racket/list
0.103u 0.029s 0:00.13 92.3% 0+0k 0+0io 0pf+0w
laptop% time racket -l racket
0.155u 0.041s 0:00.19 100.0% 0+0k 0+0io 0pf+0w
Footprint and startup time are the main reasons to use `racket/base`
plus explicit imports instead of `racket`.