HIRAUCHI Hideyuki
hira****@verys*****
2004年 2月 22日 (日) 00:38:56 JST
平内です。 ioまわりのベンチ書いてみました。 タブ区切りで結果を出力します。 2点、やり方が分からず挫折。 1. 小数点3桁未満を切り捨る方法 2. CPU、メモリ情報の取得方法 --hira (use gauche.time) (use gauche.threads) (define loop-count 300) (define-syntax with-timer (syntax-rules () ((_ i/o proc port e1 e2 ...) (let1 tc4 (list (make <real-time-counter>) (make <user-time-counter>) (make <system-time-counter>) (make <process-time-counter>)) (dynamic-wind (lambda () (for-each time-counter-start! tc4)) (lambda () e1 e2 ...) (lambda () (for-each time-counter-stop! tc4))) (cons i/o (cons proc (cons port (map time-counter-value tc4)))))))) (define (bench w-name writer r-name reader) (define (call/tmp1-out proc) (call-with-output-file "tmp1.o" (lambda (p) (proc p)))) (define (call/tmp1-in proc) (call-with-input-file "tmp1.o" (lambda (p) (proc p)))) (define ostrp #f) (define (call/strp-out proc) (set! ostrp (open-output-string)) (proc ostrp)) (define (call/strp-in proc) (define str (get-output-string ostrp)) ;(print str) (proc (open-input-string str))) (define (write-test port call/out) (with-timer "O" w-name port (dotimes (i loop-count) (call/out (lambda (p) (dotimes (i loop-count) (writer p))))))) (define (read-test port call/in) (with-timer "I" r-name port (dotimes (i loop-count) (call/in (lambda (p) (do () ((eof-object? (reader p))))))))) (list (write-test "string" call/strp-out) (read-test "string" call/strp-in) (write-test "file" call/tmp1-out) (read-test "file" call/tmp1-in) )) (define (n->s val) (if (string? val) val (rxmatch-substring (#/.{0,5}/ (number->string val)) 0))) (define (result ls) (define (result head . tail) (display (n->s head)) (if (null? tail) (newline) (begin (display "\t") (apply result tail)))) (for-each (lambda (ls) (apply result ls)) ls)) (print "date\t" (sys-strftime "%Y-%m-%d %H:%M:%S" (sys-localtime (current-time)))) (print "version\t" (gauche-version)) (print "arc\t" (gauche-architecture)) (print "lib-dir\t" (gauche-library-directory)) (print "arc-dir\t" (gauche-architecture-directory)) (print "site-lib-dir\t" (gauche-site-library-directory)) (print "site-arc-dir\t" (gauche-site-architecture-directory)) (print "thread-type\t" (gauche-thread-type)) (print "loop-count\t" loop-count) (print "") (print "I/O\tname\tport\treal\tuser\tsystem\tprocess") (result (bench "newline" (lambda (p) (newline p)) "read-line" (lambda (p) (read-line p)))) (result (bench "write-byte" (lambda (p) (write-byte #xA5 p)) "read-byte" (lambda (p) (read-byte p)))) (result (bench "write-char" (lambda (p) (write-char #\c p)) "read-char" (lambda (p) (read-char p)))) (result (bench "display" (lambda (p) (display "d" p)) "read-block(1)" (lambda (p) (read-block 1 p)))) (result (bench "format" (lambda (p) (format p "f" )) "read-block(4096)" (lambda (p) (read-block 4096 p)))) (result (bench "write-ss" (lambda (p) (write/ss #x5A p)) "read-ss" (lambda (p) (read/ss p))))