-
-
Save gcr/4a5661dfad984cfdab19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require racket/draw net/url) | |
(define bm1 | |
(call/input-url (string->url "http://i.imgur.com/RU8MN.png") get-pure-port | |
;; Just a 500x500 image | |
(λ (in) (make-object bitmap% in 'unknown/alpha)))) | |
(define width (send bm1 get-width)) | |
(define height (send bm1 get-height)) | |
(define bytes (make-bytes (* 4 width height))) | |
(send bm1 get-argb-pixels 0 0 width height bytes #f #t) | |
(define bm (make-object bitmap% width height #f #t)) | |
(define (one-run) | |
(define-values (results cpu real gc) | |
(time-apply (λ() (send bm set-argb-pixels 0 0 width height | |
bytes #f #t)) | |
'())) | |
real) | |
(one-run) ; warm up the JIT | |
(display "Running tests") | |
(define times (for/list ([i (in-range 20)]) | |
(display ".") (flush-output) | |
(one-run))) | |
(define average (exact->inexact (/ (apply + times) (length times)))) | |
(define stddev (sqrt (/ (for/sum ([time times]) (sqr (- time average))) | |
(sub1 (length times))))) | |
(define std-err-of-mean (/ stddev (sqrt (length times)))) | |
(set! std-err-of-mean (/ (floor (* std-err-of-mean 10.0)) 10.0)) | |
(printf "\n~a ± ~a msec\n" average std-err-of-mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment