Changeset 39386 in project
- Timestamp:
- 11/25/20 20:44:32 (5 months ago)
- Location:
- release/5/micro-benchmark/trunk/tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
release/5/micro-benchmark/trunk/tests/micro-benchmark-test-utils.scm
r39344 r39386 3 3 ;; 4 4 5 (import (only (chicken string) ->string))6 7 5 (define-syntax test-bigO 8 6 (syntax-rules () 9 7 ((_ ?O ?expr) 10 (test-bigO ( ->string?expr) ?O ?expr) )8 (test-bigO ((let () (import (only (chicken string) ->string)) ->string) ?expr) ?O ?expr) ) 11 9 ((_ ?msg ?O ?expr) 12 10 (test-assert ?msg (bigO= ?O ?expr)) ) ) ) … … 14 12 ;; 15 13 16 (import (chicken time posix)) 14 ;NOTE (sleep i) seems to actually sleep i-1 seconds on windows 15 (define-constant SLEEP-TIME 2) 17 16 18 ;NOTE (sleep i) seems to actually sleep i-1 seconds on windows 19 (define SLEEP-TIME 2) 20 21 (define (busy-work) (sleep SLEEP-TIME)) 17 (define (busy-work) 18 (import (chicken time posix)) 19 (sleep SLEEP-TIME) ) 22 20 23 21 ;; 24 22 25 (import (only (chicken base) alist-ref))26 27 23 (define-syntax stats-item 28 24 (syntax-rules () 29 ((_ ?key ?stats) 30 (stats-ref ?stats '?key) ) ) ) 25 ((stats-item ?key ?stats) (stats-ref ?stats '?key)) ) ) 31 26 32 (define (stats-ref stats key) (alist-ref key stats)) 27 (define (stats-ref stats key) 28 (import (only (chicken base) alist-ref)) 29 (alist-ref key stats) ) 33 30 34 31 (define (bigO-stats-test expO stats key) -
release/5/micro-benchmark/trunk/tests/micro-benchmark-test.scm
r39379 r39386 13 13 (define (wait-message) (gloss "Please Wait ...")) 14 14 15 ;; 16 15 17 (test-begin "micro-benchmark") 16 18 … … 19 21 20 22 ;; 23 24 (define (ÎŒs->secs ÎŒs) (/ ÎŒs 1000000.0)) 21 25 22 26 (import (only micro-stats generate-statistics)) … … 29 33 ) 30 34 31 (test-group "examples" 32 (import (only (chicken base) sleep)) 35 (parameterize ((current-test-epsilon 0.001) 36 (current-benchmark-statistics-set #t) 37 (current-benchmark-iterations 3) ) 33 38 34 ;simply measure the runtime of the given fragment 35 (wait-message) 36 (test-assert (glossed (benchmark-measure (sleep 2)))) 37 (glossed) 39 (test-group "benchmark-measure" 40 (wait-message) 41 (test-bigO "benchmark-measure returns runtime" 42 1000000.0 (benchmark-measure (busy-work) 'test)) 43 ) 38 44 39 ;run code 3 times and return results40 (wait-message)41 (parameterize ((current-benchmark-iterations 3))42 (test-assert (glossed (benchmark-run (sleep 1))))43 (glossed))44 45 ;find out how many iterations we can make per second46 (wait-message)47 (test-assert (glossed (benchmark-ips (sleep 2))))48 (glossed)49 )50 51 (parameterize ((current-test-epsilon 0.001)52 (current-benchmark-statistics-set #t) )53 ;54 (wait-message)55 (test-bigO "benchmark-measure returns runtime"56 1000000.0 (benchmark-measure (busy-work) 'test))57 ;58 45 (test-group "benchmark-run" 59 46 (let ( … … 61 48 (let ( 62 49 (runs 63 ( parameterize ((current-benchmark-iterations 3))50 (begin 64 51 (wait-message) 65 52 (benchmark-measure-run (begin (busy-work) 'test)))) ) … … 70 57 95th 71 58 arithmetic-mean harmonic-mean geometric-mean median mode)) ) 72 ; 59 73 60 (let ((stats (benchmark-run (1) #t))) 74 61 (test "deviation for a single result" 0.0 (stats-item sd stats)) … … 77 64 ) 78 65 66 (parameterize ((current-test-epsilon 0.009) 67 (current-benchmark-iterations 3) ) 68 (test-group "examples" 69 (import (only (chicken base) sleep)) 70 71 ;simply measure the runtime of the given fragment 72 (wait-message) 73 (test 2.00 (ÎŒs->secs (benchmark-measure (sleep 2)))) 74 75 ;run code 3 times and return results 76 (wait-message) 77 (test 1.00 (ÎŒs->secs (stats-item mean (benchmark-run (sleep 1))))) 78 79 ;find out how many iterations we can make per second 80 (wait-message) 81 (test 0.5 (* 0.1 (round (* 10.0 (stats-item mean (benchmark-ips (sleep 2))))))) 82 ) 83 ) 84 79 85 (test-end "micro-benchmark") 80 86
Note: See TracChangeset
for help on using the changeset viewer.