Changeset 39347 in project


Ignore:
Timestamp:
11/23/20 03:04:07 (5 months ago)
Author:
Kon Lovett
Message:

add exmaples to test, fix original API syntax, ips syntax returns stats, fix 100ms

Location:
release/5/micro-benchmark/trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • release/5/micro-benchmark/trunk/micro-benchmark.scm

    r39346 r39347  
    5656;(: benchmark-ips (sexp -> (or boolean statistics-alist)))
    5757(: run-benchmark-measure (procedure -> number))
    58 (: run-benchmark-ips (procedure #!optional real real -> runtimes))
    59 (: iterations-per-100ms (procedure real -> real number))
     58(: run-benchmark-ips (procedure #!optional (or false real) (or false real) -> runtimes))
     59(: iterations-per-100ms (procedure real -> fixnum number))
    6060
    6161;;;
     
    136136    obj) )
    137137
    138 ;;;
    139 
    140 ;;
     138;from mathh.scm
    141139
    142140(define (log-with-base b)
     
    147145(define log10 (log-with-base 10))
    148146
     147;;;
     148
    149149(define (secs->ms secs) (* secs 1000))
    150150
    151 (define (secs->exact-ms secs) (inexact->exact (round (secs->ms secs))))
     151(define (->exact x) (inexact->exact (round x)))
    152152
    153153;;
     
    244244    ;
    245245    ((benchmark-ips (?thresholds ?warmups) ?code0 ?code1 ...)
    246       (benchmark-measure-ips (?thresholds ?warmups) ?code0 ?code1 ...) )
     246      (benchmark-ips (?thresholds ?warmups (current-benchmark-statistics-set-id)) ?code0 ?code1 ...) )
     247    ;
     248    ((_ (?thresholds ?warmups ?stat-set-id) ?code0 ?code1 ...)
     249      (let ((observed (benchmark-measure-ips (?thresholds ?warmups) ?code0 ?code1 ...)))
     250        (generate-statistics observed ?stat-set-id) ) )
    247251    ;C4 API
    248252    ((benchmark-ips ?code)
     
    292296    (warmups (or warmups DEFAULT-WARMUPS)) )
    293297    (let-values (
    294       ((per-100ms _) (iterations-per-100ms thunk (secs->exact-ms warmups)))
    295       ((threshold) (+ (secs->exact-ms thresholds) (current-milliseconds))) )
    296       (let loop ((iterations 0) (timings (list)))
    297         (assume ((per-100ms fixnum) (iterations fixnum))
    298           (if (< threshold (current-milliseconds))
    299             (map (lambda (i) (/ per-100ms (/ i 1000.0))) timings)
     298      ((per-100ms _) (iterations-per-100ms thunk (secs->ms warmups)))
     299      ((threshold) (+ (current-milliseconds) (secs->ms thresholds))) )
     300      (assume ((per-100ms fixnum))
     301        (let loop ((iterations (the fixnum 0)) (timings (list)))
     302          (if (< (current-milliseconds) threshold)
    300303            (let* (
    301304              (before (current-milliseconds))
    302305              (_ (dotimes (tmp per-100ms) (thunk)))
    303306              (after  (current-milliseconds)) )
    304               (loop (+ iterations per-100ms) (cons (- after before) timings))) ) ) ) ) ) )
     307              (loop (+ iterations per-100ms) (cons (- after before) timings)))
     308            (map (lambda (i) (/ per-100ms (/ i 1000))) timings) ) ) ) ) ) )
     309
     310;any overhead
     311(define *iterations-overhead* 0.0)
    305312
    306313;calc any overhead
    307 (define *iterations-overhead* 0)
    308314(define-constant OVERHEAD-ITERATIONS 10000000)
    309315(let ((before (current-milliseconds)))
     
    325331    (before (current-milliseconds))
    326332    (threshold (+ limit before)) )
    327     (let loop ((iterations 0))
     333    (let loop ((iterations (the fixnum 0)))
    328334      (cond
    329335        ((< (current-milliseconds) threshold)
     
    333339          (let* (
    334340            (after (current-milliseconds))
    335             (total-time (max 0 (- after before (* iterations *iterations-overhead*))))
    336             (per-100ms (inexact->exact (round (* (/ iterations total-time) 100)))) )
    337             (values (min 0 per-100ms) total-time) ) ) ) ) ) )
     341            (overhead (->exact (* iterations *iterations-overhead*)))
     342            (total-time (max 0 (- after before overhead)))
     343            (per-100ms (* (/ iterations total-time) 100)) )
     344            (values (max 0 per-100ms) total-time) ) ) ) ) ) )
    338345
    339346;;DEPRECATED
  • release/5/micro-benchmark/trunk/tests/micro-benchmark-test.scm

    r39344 r39347  
    1111;;
    1212
    13 (import
    14   (prefix (only sequences coerce) seq:)
    15   (only micro-stats generate-statistics))
     13(import (only micro-stats generate-statistics))
    1614
    1715(test-begin "micro-benchmark")
     
    4644      (gloss stats) )
    4745  )
     46  ;
     47  (test-group "examples"
     48    (import (only (chicken base) sleep))
     49    ;simply measure the runtime of the given fragment
     50    (gloss "(benchmark-measure (sleep 2))")
     51    (gloss (benchmark-measure (sleep 2)))
     52    ;run code 3 times and return results
     53    (gloss "(gloss (benchmark-run (sleep 1)))")
     54    (parameterize ((current-benchmark-iterations 3))
     55      (gloss (benchmark-run (sleep 1))))
     56    ;find out how many iterations we can make per second
     57    (gloss "(benchmark-ips (sleep 2))")
     58    (gloss (benchmark-ips (sleep 2)))
     59  )
    4860)
    4961
Note: See TracChangeset for help on using the changeset viewer.