Load handles operations that read data from the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: RAM PERFORMANCE code/opt/lower.c 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 /* Convert string to lower case: slow */ void lower1(char *s) { int i; for (i = 0; i < strlen(s); i++) if (s[i] >= ’A’ && s[i] <= ’Z’) s[i] -= (’A’ - ’a’); } /* Convert string to lower case: faster */ void lower2(char *s) { int i; int len = strlen(s); for (i = 0; i < len; i++) if (s[i] >= ’A’ && s[i] <= ’Z’) s[i] -= (’A’ - ’a’); } /* Implementation of library function strlen */ /* Compute length of string */ size_t strlen(const char *s) { int length = 0; while (*s != ’\0’) { s++; length++; } return length; } code/opt/lower.c Figure 5.7: Lower-Case Conversion Routines. The two procedures have radically different performance. 5.4. ELIMINATING LOOP INEFFICIENCIES 215 250 200 CPU Seconds 150 lower1 100 50 lower2 0 0 50000 100000 150000 200000 250000 String Length Function lower1 lower2 8,192 0.15 0.0002 16,384 0.62 0.0004 String Length 32,768 65,53...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online