Final version, much better performance, tested on examples

This commit is contained in:
Jay McCarthy 2015-09-04 09:51:11 -04:00
parent 883daf4faa
commit 0fc700c0a0
4 changed files with 3304 additions and 49 deletions

View File

@ -21,8 +21,6 @@
;; This is really bad. The goal should be for the counts for ;; This is really bad. The goal should be for the counts for
;; word-(evt,output,label,fps) to all be the same as tick ;; word-(evt,output,label,fps) to all be the same as tick
;; ;;
;; The second release was this:
;;
;; [log.2] ;; [log.2]
;; 844 Events ;; 844 Events
;; word-event: #179, average gap 27.584044724367978 ;; word-event: #179, average gap 27.584044724367978
@ -33,11 +31,27 @@
;; word-return: #1, average gap 0 ;; word-return: #1, average gap 0
;; word-tick: #132, average gap 37.29275442807729 ;; word-tick: #132, average gap 37.29275442807729
;; ;;
;; [log.3]
;; 1997 Events
;; word-event: #492, average gap 22.231684480810845
;; word-evt: #301, average gap 36.38639729817708
;; word-fps: #301, average gap 36.386416829427084
;; word-label: #301, average gap 36.440130208333336
;; word-output: #301, average gap 37.64551025390625
;; word-return: #1, average gap 0
;; word-tick: #300, average gap 36.4600801499791
;;
;; [log.4]
;; 1231 Events
;; word-event: #306, average gap 22.516072457735657
;; word-evt: #185, average gap 37.325081203294836
;; word-fps: #185, average gap 37.32514091159987
;; word-label: #185, average gap 37.34000562584919
;; word-output: #185, average gap 39.36237501061481
;; word-return: #1, average gap 0
;; word-tick: #184, average gap 37.38046981728142
(module+ main (define (check log-p)
(require racket/runtime-path)
(define-runtime-path log-p "log")
(define events (file->list log-p)) (define events (file->list log-p))
(printf "~a Events\n" (length events)) (printf "~a Events\n" (length events))
@ -64,11 +78,18 @@
(define t (first ts)) (define t (first ts))
(cons (- t last) (cons (- t last)
(loop t (rest ts)))]))) (loop t (rest ts)))])))
(define (average-gap ts) (define (average-gap ts)
(average (gaps ts))) (average (gaps ts)))
(for ([(i ts) (in-hash label->times)]) (for ([i (in-list (sort (hash-keys label->times) string<=? #:key symbol->string))])
(define ts (hash-ref label->times i))
(printf "~a: #~a, average gap ~a\n" (printf "~a: #~a, average gap ~a\n"
i i
(length ts) (length ts)
(average-gap ts)))) (average-gap ts))))
(module+ main
(require racket/cmdline)
(command-line #:program "log-check"
#:args (log-p)
(check log-p)))

1997
log.3 Normal file

File diff suppressed because it is too large Load Diff

1231
log.4 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -67,62 +67,68 @@
(define next-time (fl+ start-time time-incr)) (define next-time (fl+ start-time time-incr))
next-time) next-time)
(define (continue-or-word-return next-w old-w k)
(cond
[(not next-w)
(word-return old-w)]
[else
(k next-w)]))
(define (factum-fiat-lux c w) (define (factum-fiat-lux c w)
(define (continue-or-word-return next-w old-w k)
(cond
[(not next-w)
((LOG! word-return) old-w)]
[else
(k next-w)]))
(define (output&process-input&wait frame-start-time w) (define (output&process-input&wait frame-start-time w)
(chaos-output! c ((LOG! word-output) w)) (chaos-output! c (word-output w))
(define frame-end-time (current-inexact-milliseconds)) (define frame-end-time (current-inexact-milliseconds))
(define frame-time (- frame-end-time frame-start-time)) (define frame-time (- frame-end-time frame-start-time))
(define new-label ((LOG! word-label) w frame-time)) (define new-label (word-label w frame-time))
(chaos-label! c new-label) (chaos-label! c new-label)
(define fps ((LOG! word-fps) w)) (define fps (word-fps w))
(define next-time (compute-next-time frame-end-time fps)) (define next-time (compute-next-time frame-end-time fps))
(define deadline-evt (alarm-evt next-time)) (define deadline-evt (alarm-evt next-time))
(define input-enabled? (zero? fps)) (define input-enabled? (fl= 0.0 fps))
(define w-evt ((LOG! word-evt) w)) (define w-evt (word-evt w))
(define c-evt (chaos-event c)) (define c-evt (chaos-event c))
(define w-or-c-evt (choice-evt w-evt c-evt)) (define w-or-c-evt (choice-evt w-evt c-evt))
(let process-input&wait ([w w]) (define continue
(define wait-evt (λ (next-w)
(handle-evt deadline-evt (output&process-input&wait frame-end-time next-w)))
(λ (_)
(define next-w ((LOG! word-tick) w)) (define THE-W w)
(continue-or-word-return (define wait-evt
next-w w (handle-evt deadline-evt
(λ (next-w) (λ (_)
(output&process-input&wait frame-end-time next-w)))))) (define next-w (word-tick THE-W))
(define input-evt (continue-or-word-return
(handle-evt w-or-c-evt next-w THE-W
(λ (e) continue))))
(define next-w ((LOG! word-event) w e)) (define input-continue
(continue-or-word-return (λ (next-w)
next-w w (cond
(λ (next-w) [input-enabled?
(if input-enabled? (output&process-input&wait frame-end-time next-w)]
(output&process-input&wait frame-end-time next-w) [else
(process-input&wait next-w))))))) (set! THE-W next-w)
(define both-evt (process-input&wait)])))
(choice-evt input-evt wait-evt)) (define input-evt
(sync/timeout (handle-evt w-or-c-evt
(λ () (chaos-yield c both-evt)) (λ (e)
input-evt))) (define next-w (word-event THE-W e))
(continue-or-word-return
next-w THE-W
input-continue))))
(define both-evt
(choice-evt input-evt wait-evt))
(define timeout-f
(λ () (chaos-yield c both-evt)))
(define (process-input&wait)
(sync/timeout timeout-f input-evt))
(process-input&wait))
(chaos-swap! c (λ () (output&process-input&wait (current-inexact-milliseconds) w)))) (chaos-swap! c (λ () (output&process-input&wait (current-inexact-milliseconds) w))))
(define-syntax-rule (LOG! id)
(begin (LOG!* 'id) id))
(define (LOG!* i)
(writeln (cons (current-inexact-milliseconds) i))
(flush-output))
(provide (provide
gen:word gen:word
(contract-out (contract-out