I think that would be because "the *draw* is called during the dynamic extent of the call to dc <http://docs.racket-lang.org/pict/Basic_Pict_Constructors.html?q=dc#%28def._%28%28lib._pict%2Fmain..rkt%29._dc%29%29> as part of the contract checking."
-Philip On Sat, Apr 29, 2017 at 2:58 AM, Daniel Prager <daniel.a.pra...@gmail.com> wrote: > Thanks for all the suggestions. > > I was able to get pict down to "direct to dc"-like performance by making a > custom pict that calls my direct-to-dc code ... > > (define (pict:render block) > (pict:dc (λ (dc dx dy) > (define old-brush (send dc get-brush)) > (define old-pen (send dc get-pen)) > (dc:draw dc block dx dy) > (send dc set-brush old-brush) > (send dc set-pen old-pen)) > (* *size* *n*) (* *size* *n*))) > > > My only remaining question is why pict calls the custom code on > construction, as well as on rendering. > > (displayln "Render, then convert to bitmap%...") > (define pict:c1 (time (pict:render b1))) > (define p1 (time (pict->bitmap% pict:c1))) > > > Dan > > > Revised timings ... > > > SQUARES > ======= > > 2htdp/image > ----------- > Render, then convert to bitmap%... > cpu time: 134 real time: 136 gc time: 46 > cpu time: 344 real time: 355 gc time: 60 > > pict > ---- > Render, then convert to bitmap%... > cpu time: 80 real time: 87 gc time: 0 > cpu time: 83 real time: 84 gc time: 13 > > direct to dc > ------------ > Render direct to bitmap%... > cpu time: 67 real time: 68 gc time: 0 > > > TRIANGLES > ========= > > 2htdp/image > ----------- > Method 1 - Render, then convert to bitmap%... > cpu time: 542 real time: 559 gc time: 76 > cpu time: 606 real time: 622 gc time: 63 > > Method 2 - Render, then convert to bitmap%... > cpu time: 332 real time: 337 gc time: 51 > cpu time: 539 real time: 550 gc time: 62 > > Method 3 - Render, then convert to bitmap%... > cpu time: 223 real time: 230 gc time: 37 > cpu time: 276 real time: 279 gc time: 25 > > > pict > ---- > Render, then convert to bitmap%... > cpu time: 176 real time: 173 gc time: 22 > cpu time: 188 real time: 188 gc time: 9 > > direct to dc > ------------ > Render direct to bitmap%... > cpu time: 193 real time: 194 gc time: 16 > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.