README revision 1.1 1 1.1 christos This directory contains some examples illustrating techniques for extracting
2 1.1 christos high-performance from flex scanners. Each program implements a simplified
3 1.1 christos version of the Unix "wc" tool: read text from stdin and print the number of
4 1.1 christos characters, words, and lines present in the text. All programs were compiled
5 1.1 christos using gcc (version unavailable, sorry) with the -O flag, and run on a
6 1.1 christos SPARCstation 1+. The input used was a PostScript file, mainly containing
7 1.1 christos figures, with the following "wc" counts:
8 1.1 christos
9 1.1 christos lines words characters
10 1.1 christos 214217 635954 2592172
11 1.1 christos
12 1.1 christos
13 1.1 christos The basic principles illustrated by these programs are:
14 1.1 christos
15 1.1 christos - match as much text with each rule as possible
16 1.1 christos - adding rules does not slow you down!
17 1.1 christos - avoid backing up
18 1.1 christos
19 1.1 christos and the big caveat that comes with them is:
20 1.1 christos
21 1.1 christos - you buy performance with decreased maintainability; make
22 1.1 christos sure you really need it before applying the above techniques.
23 1.1 christos
24 1.1 christos See the "Performance Considerations" section of flexdoc for more
25 1.1 christos details regarding these principles.
26 1.1 christos
27 1.1 christos
28 1.1 christos The different versions of "wc":
29 1.1 christos
30 1.1 christos mywc.c
31 1.1 christos a simple but fairly efficient C version
32 1.1 christos
33 1.1 christos wc1.l a naive flex "wc" implementation
34 1.1 christos
35 1.1 christos wc2.l somewhat faster; adds rules to match multiple tokens at once
36 1.1 christos
37 1.1 christos wc3.l faster still; adds more rules to match longer runs of tokens
38 1.1 christos
39 1.1 christos wc4.l fastest; still more rules added; hard to do much better
40 1.1 christos using flex (or, I suspect, hand-coding)
41 1.1 christos
42 1.1 christos wc5.l identical to wc3.l except one rule has been slightly
43 1.1 christos shortened, introducing backing-up
44 1.1 christos
45 1.1 christos Timing results (all times in user CPU seconds):
46 1.1 christos
47 1.1 christos program time notes
48 1.1 christos ------- ---- -----
49 1.1 christos wc1 16.4 default flex table compression (= -Cem)
50 1.1 christos wc1 6.7 -Cf compression option
51 1.1 christos /bin/wc 5.8 Sun's standard "wc" tool
52 1.1 christos mywc 4.6 simple but better C implementation!
53 1.1 christos wc2 4.6 as good as C implementation; built using -Cf
54 1.1 christos wc3 3.8 -Cf
55 1.1 christos wc4 3.3 -Cf
56 1.1 christos wc5 5.7 -Cf; ouch, backing up is expensive
57