Program Performance - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Program Performance

Description:

Western Washington University. 2. Program Performance ... Data space (Data Segment and Extra Segment) Environment stack space (Stack Segment) ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 15
Provided by: anniegro
Category:

less

Transcript and Presenter's Notes

Title: Program Performance


1
Program Performance
  • CS341
  • Western Washington University

2
Program Performance
  • Program performance is the amount of computer
    memory and time needed to run a program
  • How is it determined?
  • Analytically
  • Performance Analysis
  • Experimentally
  • Performance Measurement

3
Space Complexity
Space Complexity is defined as the amount of
memory a program needs to run to
completion. Why is this of concern? We could
be running on a multi-user system where programs
are allocated a specific amount of space. We
may not have sufficient memory on our
computer. There may be multiple solutions, each
having different space requirements. The space
complexity may define an upper bound on the data
that the program can handle.
4
Components of Program Space
Recall your course in Computer Organization Inst
ruction space (Code Segment) Data space (Data
Segment and Extra Segment) Environment stack
space (Stack Segment) The instruction space is
dependent on several factors - the compiler that
generated the machine code - the compiler options
that were set at compilation time - the target
computer (whats its architecture?)
5
The Data Space is also very much dependent on the
computer architecture and compiler.
The magnitude of the data that a program
works with is another factor. Consider the
following list of bytes per type Type
Space(bytes) char 1 short 2 int 4 long 8 fl
oat 4 double 8 long double 10 pointer 4 Thus
, choosing a smaller data type has an effect on
the overall space usage of the program. Choosing
the correct type is especially important when
working with arrays. How much memory is
allocated with these declarations double
a100 char buf80
6
Lets review what happens in the
Environment space(SS). Every time a function is
called, the following data are saved on the
stack - the return address (IP) - the values of
all local variables and value formal
parameters - the binding of all reference and
const reference parameter What is the impact
of recursive function calls on the Environment
space?
7
Space Complexity Summary
Given what you now know about space complexity,
what can you do differently to make your
programs more space efficient? Always choose the
optimal(smallest necessary) data type Study the
compiler. Learn about the effects of different
compilation settings. Choose non-recursive
algorithms when appropriate. Embed assembly
instructions in your code -)
8
Time Complexity
Time complexity is the amount of computer time a
program needs to run. Why do we care about time
complexity? Some computers require upper limits
for program execution times. Some programs
require a real time response. If there are many
solutions to a problem, typically wed like to
choose the quickest.
9
Time Complexity Components
Time complexity is dependent on all the
factors that space complexity is dependent on -
Compiler settings - Computer Architecture(instruct
ion set) - Processor speed - RAM Additionally,
it is dependent on the types of operations and
the data that is being operated on. Why does
this matter? In order to estimate the run time,
it can be useful to identify key operations(I.e.
add, compare, etc) and count the number of
times each is performed.
10
Consider a function MaxElement template ltclass
Tgt int MaxElement(T a, int len) int pos
for (int index1 index lt len index)
if (apos lt aindex) pos index
return pos Identify the key
operations and count them.
11
For certain programs, the data set has a
large impact on the time complexity of the
program. Searching and Sorting! Because of
this, there is a need to count the number of
operations for the Worst case, the Best case, and
the Average case. Consider an Insert function
that inserts into a sorted array template
ltclass Tgt void Insert(T a, int len, const T
item) for (int indexlen-1 (indexgt0)
(item lt aindex) index)
aindex1 aindex aindex1 item
len
12
What is the best case? Count the steps in that
case. What is the worst case? Count the steps
in that case. What is the average case? We
use asymptotic notation to talk about
these bounds.
13
Practical Complexities
Once we have identified the order of magnitude of
a program, using asymptotic notation, we still
need to consider the data we are
working with. Study the following table logn
n nlogn n2 n3 2n 0 1 0 1 1 2 1 2 2 4 8 4 2 4 8 16
64 16 3 8 24 64 512 256 4 16 64 256 4096 65536 5
32 160 1024 32768 4294967296 Overly complex
programs may not be practical given the computing
power of the system. Suppose a computer can
perform 1,000,000,000 instructions per second,
and algorithm F is O(n10). When n10,
the program requires 3171 to execute.
14
Performance Measurement
Performance measurement is where we
actually obtain the space and time requirements
for a program in an experimental setting. To
obtain the space requirements - the size of the
instruction and data space are provided by the
compiler, post -compilation - we can measure the
environment stack using analytical methods To
obtain the time requirements - use a clocking
mechanism. - develop test datausually best,
worst, and average-case data - develop a test
program
Write a Comment
User Comments (0)
About PowerShow.com