thorough guide for profiling racket code -


did googling ("racket profiling", "racket measure performance"), didn't find , there no examples in docs. did google "profile" search on htdp - no luck. (profile (f ...)) output isn't obvious other small snippets.

ideally want python's python -m cprofile usage examples.

when search "python profiling", both duckduckgo , google give top result: 26.4. python profilers.

(although scanned quickly, seems more of reference "thorough usage guide" examples. if had else in mind, perhaps please link that?)

the equivalent racket documentation be: profile: statistical profiler.

a usage example:

#lang racket (require profile) (profile-thunk (thunk (function-to-profile arg0 arg1) )) 

here (thunk e) convenience (lambda () e).


bigger example:

#lang racket  (module mod racket   (provide f)   (define (f)     (for/list ([i 10000])       i)))  (require (prefix-in mod: 'mod))  (define (f)   (for ([i 10000])     (mod:f)))  (require profile) (profile-thunk f) 

for me outputs:

profiling results -----------------   total cpu time observed: 5666ms (out of 5753ms)   number of samples taken: 105 (once every 54ms)  ========================================================                                caller idx   total        self      name+src             local%       ms(pct)      ms(pct)     callee ======================================================== [1] 5666(100.0%)    0(0.0%)  [running body] /tmp/profile.rkt:##f                                profile-thunk14 [2]100.0% --------------------------------------------------------                                [running body] [1] 100.0% [2] 5666(100.0%)    0(0.0%)  profile-thunk14 ...e-pkgs/profile-lib/main.rkt:9:0                                run [3]            100.0% --------------------------------------------------------                                profile-thunk14 [2]100.0% [3] 5666(100.0%)    0(0.0%)  run ...pkgs/profile-pkgs/profile-lib/main.rkt:31:2                                for-loop [4]       100.0% --------------------------------------------------------                                run [3]            100.0% [4] 5666(100.0%) 1630(28.8%) for-loop /tmp/profile.rkt:12:2                                f [5]               71.2% --------------------------------------------------------                                for-loop [4]       100.0% [5] 4036(71.2%)  1786(31.5%) f /tmp/profile.rkt:5:2                                for-loop [6]        55.8% --------------------------------------------------------                                f [5]              100.0% [6] 2250(39.7%)  2250(39.7%) for-loop /tmp/profile.rkt:6:4 -------------------------------------------------------- 

note show line numbers, though there 2 functions named f, possible see 1 -- , in fact part of each one.


also recommend optimization coach package. although give different insights traditional profiler, gives specific suggestions how change code faster. by-product teaches how write way in first place.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -