File: sgrep.scm

package info (click to toggle)
chicken 5.3.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,892 kB
  • sloc: ansic: 580,083; lisp: 71,987; tcl: 1,445; sh: 588; makefile: 60
file content (36 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;;;; sgrep.scm - grepping benchmark


(import chicken.io chicken.irregex chicken.port)


(define big-string
  (with-input-from-file (optional (command-line-arguments) "compiler.scm") read-string))

(define-syntax bgrep
  (syntax-rules ()
    ((_ n expr)
     (time
      (do ((i n (fx- i 1)))
	  ((eq? i 0))
	(with-input-from-string big-string
	  (lambda ()
	    (let ((h 0)
		  (c 0))
	      (do ((line (read-line) (read-line)))
		  ((eof-object? line))
		(set! c (fx+ c 1))
		;(when (zero? (fxmod c 500)) (print* "."))
		(when (irregex-search expr line)
		  (set! h (fx+ h 1))))
	      h))))))))

(define-syntax rx1
  (syntax-rules ()
    ((_) "\\((.*), (.*)\\)")))

(define-syntax rx2
  (syntax-rules ()
    ((_) '(: #\( (submatch (* any)) ", " (submatch (* any))))))

(bgrep 1 (rx1))