Page 180 - ARM 64 Bit Assembly Language
P. 180

Abstract data types  167

                                     Listing 6.9 Revised makefile for the wordfreq program.

                    1  C_OBJS=wordfreq.o list.o
                    2  ASM_OBJS=wl_print_numerical.o
                    3  OBJS=$(C_OBJS) $(ASM_OBJS)
                    4
                    5  CC=aarch64-linux-gnu-gcc
                    6  LFLAGS=-O2 -g
                    7  CFLAGS=-I. -O2 -g -Wall
                    8  SFLAGS=-I. -O2 -g -Wall
                    9  DEPENDFLAGS=-I. -M
                   10
                   11  wordfreq: $(OBJS)
                   12         $(CC) $(LFLAGS) -o wordfreq $(OBJS)
                   13
                   14  .S.o:
                   15         $(CC) $(SFLAGS) -c $<
                   16
                   17  .c.o:
                   18         $(CC) $(CFLAGS) -c $<
                   19
                   20  clean:
                   21         rm -f *.o *~ wordfreq
                   22
                   23  # make depend will create a file ".depend" with all the dependencies
                   24  depend:
                   25         rm -f .depend
                   26         $(CC) $(DEPENDFLAGS) $(C_OBJS:.o=.c) > .depend
                   27
                   28  # if we have a .depend file, include it
                   29  ifeq (.depend,$(wildcard .depend))
                   30  include .depend
                   31  endif



                     6.2.2 Better performance

                     The word frequency counter, as previously implemented, takes several minutes to count
                     the frequency of words in this textbook on a Raspberry Pi. Most of the time is spent build-
                     ing the list of words, and re-sorting the list in order of word frequency. Most of the time for
                     both of these operations is spent in searching for the word in the list before incrementing its
                     count or inserting it in the list. There are much more efficient ways to build ordered lists of
                     data.

                     Since the code is well modularized using an ADT, the internal mechanism of the list can be
                     modified without affecting the main program. A major improvement can be made by changing
                     the data structure from a linked list to a binary tree. Fig. 6.1 shows an example binary tree
   175   176   177   178   179   180   181   182   183   184   185