<div dir="ltr">Yes, the `main` version runs normally fast, while the `main2` version is slow.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 22, 2014 at 4:15 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
The attached file is from a vignette that I have been working on ("Programming with Class"). It simulates 'big-bang' without a lot of the student protections and the machinery needed to make it compatible with the stepper etc. It also cuts out some of the software engineering playing I did (but which turned out to be useful over the years).<br>
<br>
The fragment below runs your program (as far as I can tell) like the original. Could you please measure this new version of your 'funny' machine?<br>
<br>
Thanks -- Matthias<br>
<br>
#lang racket<br>
<br>
;;; Run this file with `racket test-big-bang.rkt`<br>
;;; then type quickly "asdf" to trigger several successive to-draw events.<br>
;;; Drawing the scene is fast, but rendering it on-screen is very slow?<br>
<br>
(require 2htdp/image<br>
2htdp/planetcute<br>
"bb.rkt")<br>
<br>
(define elt-width (image-width grass-block))<br>
(define elt-height (image-height grass-block))<br>
(define elt-height/2 (/ elt-height 2))<br>
<br>
(define view-width 800)<br>
(define view-height 400)<br>
(define window-width view-width)<br>
(define window-height (+ view-height elt-height))<br>
<br>
(define grid-size 10)<br>
<br>
(define (stack-rows . col-picts)<br>
(for/fold ([img empty-image])<br>
([cp col-picts])<br>
(underlay/align/offset<br>
"center" "bottom"<br>
img 0 elt-height/2 cp)))<br>
<br>
(define (client-draw-all)<br>
(apply stack-rows<br>
(for/list ([i grid-size])<br>
(apply beside/align "bottom"<br>
(for/list ([j grid-size])<br>
grass-block)))))<br>
<br>
(define t0 (current-milliseconds))<br>
(define (print-time str)<br>
(printf "~a at ~a\n" str (- (current-milliseconds) t0)))<br>
<br>
;; uncomment if you want to compare old and new<br>
#;<br>
(define (main2)<br>
(local-require 2htdp/universe)<br>
(big-bang<br>
'()<br>
(to-draw (λ(w)<br>
(print-time "to-draw")<br>
(display "to-draw: ")<br>
(time (client-draw-all)))<br>
window-width window-height)<br>
(on-key (λ(w k)(print-time (format "on-key ~a" k))))))<br>
<br>
(define (main)<br>
(send (new world%<br>
[state0 10]<br>
;; -------------------------------------------------------<br>
;; from Laurent's code<br>
[to-draw<br>
(λ(w)<br>
(print-time "to-draw")<br>
(display "to-draw: ")<br>
(time (client-draw-all)))]<br>
[on-key (λ(w k)(print-time (format "on-key ~a" k)))]<br>
;; -------------------------------------------------------<br>
[width window-width]<br>
[height window-height]<br>
[on-mouse #f])<br>
start))<br>
<br>
<br>
</blockquote></div><br></div>