Skip to content

Commit 49102bf

Browse files
committed
Add instantiation-only mode
1 parent 95d980a commit 49102bf

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

raco-tests.rkt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#lang racket/base
2+
3+
(require rackunit)
4+
(require racket/system
5+
racket/port
6+
math/statistics)
7+
8+
(define (get-total-time profiling-command)
9+
(string->number (car (regexp-match #rx"[0-9]+" (car (regexp-match #rx"/[0-9]+ ms" (with-output-to-string (lambda () (system profiling-command)))))))))
10+
11+
(for ([i (in-range 5)])
12+
(define whole-time (get-total-time "racket raco.rkt test-inputs/main.rkt"))
13+
(define instantiation-only-time (get-total-time "racket raco.rkt --instantiation-only test-inputs/main.rkt"))
14+
(check-true (> whole-time instantiation-only-time)))

raco.rkt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
(define boundary-view-file #f)
1313
(define boundary-view-key-file #f)
1414
(define report-space-efficient? #f)
15+
(define instantiation-only? #f)
16+
1517
(define file
1618
(command-line #:program (short-program+command-name)
1719
#:once-each
@@ -27,9 +29,14 @@
2729
[("--report-space-efficient")
2830
"Distinguish space-efficient contracts from non"
2931
(set! report-space-efficient? #t)]
32+
[("--instantiation-only")
33+
"Exclude setup of module imports from measurements"
34+
(set! instantiation-only? #t)]
3035
#:args (filename)
3136
filename))
3237

38+
(define visited-module (and instantiation-only? (module-to-profile file)))
39+
3340
(collect-garbage)
3441
(collect-garbage)
3542
(collect-garbage)
@@ -39,6 +46,6 @@
3946
#:boundary-view-file boundary-view-file
4047
#:boundary-view-key-file boundary-view-key-file
4148
#:report-space-efficient? report-space-efficient?
42-
(dynamic-require (module-to-profile file) #f))
49+
(dynamic-require (or visited-module (module-to-profile file)) #f))
4350

4451
(module test racket/base) ; don't run for testing

scribblings/contract-profile.scrbl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ The simplest way to use this tool is to use the @exec{raco contract-profile}
2828
command, which takes a file name as argument, and runs the contract profiler on
2929
the @racket[main] submodule of that file (if it exists), or on the module
3030
itself (if there is no @racket[main] submodule).
31+
If the @exec{--instantiation-only} flag is given, only the instantiation of the
32+
module is profiled, and the profile will not include the module's initial
33+
visitation
34+
(see @secref["mod-parse" #:doc '(lib "scribblings/reference/syntax-model.scrbl")]).
3135
The tool's output is decribed below.
3236
}
3337

test-inputs/main.rkt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#lang racket
2+
(require "u-module.rkt")
3+
4+
(define result (u-decrement 2))

test-inputs/u-module.rkt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#lang racket
2+
3+
(provide u-decrement)
4+
5+
(define (u-decrement x) (- x 1))

0 commit comments

Comments
 (0)