aboutsummaryrefslogtreecommitdiff
path: root/module/calp/benchmark/parse.scm
blob: 2ba8a7ded4486e6fd5d5968a191a8d030ba2b583 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(define-module (calp benchmark parse)
  :use-module (hnh util)
  :use-module ((hnh util path) :select (path-append))
  :use-module (glob)
  :use-module (statprof)
  :use-module (datetime)

  :use-module ((srfi srfi-1) :select (concatenate))
  :use-module ((ice-9 ftw) :select (scandir))

  :export (run-benchmark)
  )

(define (run-benchmark)
  (define all-calendar-files
    (statprof
     (lambda ()
       (display "All calendar files\n")
       (concatenate
        (map (lambda (path)
               (map
                (lambda (fname) (path-append path fname))
                (scandir path (lambda (s) (and (not (string= "." (string-take s 1)))
                                          (string= "ics" (string-take-right s 3)))))))
             (glob "~/.local/var/cal/*"))))))

  (define all-read
    (statprof
     (lambda ()
       (display "All read\n")
       (map (lambda ( fullname)
              (let ((cal (call-with-input-file fullname
                           (@@ (vcomponent formats ical parse) read-file))))
                cal))
            all-calendar-files))))

  (define tokenized
    (statprof
     (lambda ()
       (display "Tokenized\n")
       (map (lambda (one-read)
              (map (@@ (vcomponent formats ical parse) tokenize)
                   one-read))
            all-read))))

  (define parsed
    (statprof
     (lambda ()
       (display "Parsed\n")
       (map (@@ (vcomponent formats ical parse) parse) tokenized))))

  (format #t "~a files processed~%"
          (length parsed))
  )