Changeset 39386 in project


Ignore:
Timestamp:
11/25/20 20:44:32 (5 months ago)
Author:
Kon Lovett
Message:

actuals test for examples

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  
    33;;
    44
    5 (import (only (chicken string) ->string))
    6 
    75(define-syntax test-bigO
    86  (syntax-rules ()
    97    ((_ ?O ?expr)
    10      (test-bigO (->string ?expr) ?O ?expr) )
     8     (test-bigO ((let () (import (only (chicken string) ->string)) ->string) ?expr) ?O ?expr) )
    119    ((_ ?msg ?O ?expr)
    1210     (test-assert ?msg (bigO= ?O ?expr)) ) ) )
     
    1412;;
    1513
    16 (import (chicken time posix))
     14;NOTE (sleep i) seems to actually sleep i-1 seconds on windows
     15(define-constant SLEEP-TIME 2)
    1716
    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) )
    2220
    2321;;
    2422
    25 (import (only (chicken base) alist-ref))
    26 
    2723(define-syntax stats-item
    2824  (syntax-rules ()
    29     ((_ ?key ?stats)
    30       (stats-ref ?stats '?key) ) ) )
     25    ((stats-item ?key ?stats) (stats-ref ?stats '?key)) ) )
    3126
    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) )
    3330
    3431(define (bigO-stats-test expO stats key)
  • release/5/micro-benchmark/trunk/tests/micro-benchmark-test.scm

    r39379 r39386  
    1313(define (wait-message) (gloss "Please Wait ..."))
    1414
     15;;
     16
    1517(test-begin "micro-benchmark")
    1618
     
    1921
    2022;;
     23
     24(define (ÎŒs->secs ÎŒs) (/ ÎŒs 1000000.0))
    2125
    2226(import (only micro-stats generate-statistics))
     
    2933)
    3034
    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) )
    3338
    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  )
    3844
    39   ;run code 3 times and return results
    40   (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 second
    46   (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   ;
    5845  (test-group "benchmark-run"
    5946    (let (
     
    6148        (let (
    6249          (runs
    63             (parameterize ((current-benchmark-iterations 3))
     50            (begin
    6451              (wait-message)
    6552              (benchmark-measure-run (begin (busy-work) 'test)))) )
     
    7057        95th
    7158        arithmetic-mean harmonic-mean geometric-mean median mode)) )
    72     ;
     59
    7360    (let ((stats (benchmark-run (1) #t)))
    7461      (test "deviation for a single result" 0.0 (stats-item sd stats))
     
    7764)
    7865
     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
    7985(test-end "micro-benchmark")
    8086
Note: See TracChangeset for help on using the changeset viewer.