Debian Codegraph @

benchmarks/rnrs-benchmarks/tail.ss

raw
1 ;;; TAIL -- One of the Kernighan and Van Wyk benchmarks.
2
3 (library (rnrs-benchmarks tail)
4 (export main)
5 (import (rnrs) (rnrs-benchmarks))
6
7 (define inport #f)
8 (define outport #f)
9
10 (define (readline port line-so-far)
11 (let ((x (read-char port)))
12 (cond ((eof-object? x)
13 x)
14 ((char=? x #\newline)
15 (list->string (reverse
16 (cons x line-so-far))))
17 (#t (readline port (cons x line-so-far))))))
18
19 (define (tail-r-aux port file-so-far)
20 (let ((x (readline port '())))
21 (if (eof-object? x)
22 (begin
23 (display file-so-far outport)
24 (close-output-port outport))
25 (tail-r-aux port (cons x file-so-far)))))
26
27 (define (tail-r port)
28 (tail-r-aux port '()))
29
30 (define (go)
31 (set! inport (open-input-file "bib"))
32 (set! outport
33 (open-file-output-port "foo"
34 (file-options no-fail)
35 'block
36 (native-transcoder)))
37 (tail-r inport)
38 (close-input-port inport))
39
40 (define (main . args)
41 (run-benchmark
42 "tail"
43 tail-iters
44 (lambda (result) #t)
45 (lambda () (lambda () (go))))))