summaryrefslogtreecommitdiff
path: root/benchmarks/parsers.scm
blob: e4612e2e7a61ea0cdf15a378318a0ac7fc15bcf1 (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
55
56
57
58
59
60
(import intarweb chicken.string chicken.time chicken.time.posix
        chicken.port srfi-13)

(define (mk-headers . strs)
  (string-append (string-join strs "\r\n") "\r\n\r\n"))

(begin (newline)
       (print "---  Request parsing ---")
       (begin (print "Parsing a minimal HTTP/1.0 request many times")
              (let* ((str (mk-headers "GET / HTTP/1.0"
                                      "Host: 127.0.0.1:8080"
                                      "User-Agent: ApacheBench/2.3"))
                     (p (open-input-string str)))
                (time (do ((i 0 (add1 i)))
                          ((= i  100000))
                        (##sys#setslot p 10 0) ; rewind
                        (read-request p)))))

       (begin (print "Parsing a realistic HTTP/1.1 request many times")
              (let* ((str (mk-headers "GET /foo HTTP/1.1"
                                      "Host: localhost:8080"
                                      "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20140722 Firefox/24.0 Iceweasel/24.7.0"
                                      "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
                                      "Accept-Language: en-US,en;q=0.5"
                                      "Accept-Encoding: gzip, deflate"
                                      "Connection: keep-alive"))
                     (p (open-input-string str)))
                (time (do ((i 0 (add1 i)))
                          ((= i  100000))
                        (##sys#setslot p 10 0) ; rewind
                        (read-request p))))))

(begin (newline)
       (print "---  Response parsing ---")
       (begin (print "Parsing a minimal HTTP/1.0 response many times")
              (let* ((str (mk-headers "HTTP/1.0 200 OK"
                                      "Content-Length: 10"))
                     (p (open-input-string str)))
                (time (do ((i 0 (add1 i)))
                          ((= i  100000))
                        (##sys#setslot p 10 0) ; rewind
                        (read-response p)))))

       (begin (newline)
              (print "Parsing a realistic HTTP/1.1 response many times")
              (let* ((str (mk-headers
                           "HTTP/1.1 404 Not Found"
                           "Date: Tue, 19 Aug 2014 19:14:24 GMT"
                           "Server: Apache"
                           "Vary: Accept-Encoding"
                           "Content-Encoding: gzip"
                           "Content-Length: 176"
                           "Keep-Alive: timeout=15, max=100"
                           "Connection: Keep-Alive"
                           "Content-Type: text/html; charset=iso-8859-1"))
                     (p (open-input-string str)))
                (time (do ((i 0 (add1 i)))
                          ((= i  100000))
                        (##sys#setslot p 10 0) ; rewind
                        (read-response p))))))