CS320: Performance EvaluationPlotting data sets
Semi log plotsLog log plots
Analyzing Program PerformanceIn Computer Science, we plot functions describing the run time (or the memory use) of a program as a function of the input size.
We run a program for a number of input sizes and end up with performance data sets. We want to characterize these as an order of magnitude, e.g. O(n2) or O(2n) complexity, i.e., we want to look at a plot and establish its O growth behavior.
Let’s look at some examples.
Example: 3 data sets f, g and h
What kinds of functions are f, g and h?
0"
20"
40"
60"
80"
100"
120"
140"
160"
180"
1" 2" 3" 4" 5"
f"
g"
h"
n f(n) g(n) h(n)
1 2 9 22 12 18 63 36 35 244 80 68 685 150 131 162
Hard / impossible to infer
• exponential? which base?• polynomial? which degree?
WHY?
Why are functions hard to infer?
Two problems:¨Very small domain (here 1..5)
n Try to get a large data domain
¨Interpreting polynomial and exponential functions from plots is hard, they all just swoop up
Larger domain
0"
2000"
4000"
6000"
8000"
10000"
12000"
14000"
16000"
18000"
0" 2" 4" 6" 8" 10" 12" 14"
f"
g"
h"
n f(n) g(n) h(n)1 2 9 22 12 18 63 36 35 244 80 68 685 150 131 1627 400 520 62410 1100 4106 251012 1872 16396 5196
Notice that values for n=1-5are practically on the floor now, and we see differentbehavior further on. The steeper a plot, the higher its Order of Magnitude.
Larger domain
0"
2000"
4000"
6000"
8000"
10000"
12000"
14000"
16000"
18000"
0" 2" 4" 6" 8" 10" 12" 14"
f"
g"
h"
n f(n) g(n) h(n)1 2 9 22 12 18 63 36 35 244 80 68 685 150 131 1627 400 520 62410 1100 4106 251012 1872 16396 5196
Which function may be polynomial, which exponential?Still, not all clear (order, base…), h(n) may spike up later…
Straight LinesWe get the most information from straight lines!
¨ We can easily recognize a straight line (y = ax+b)n The slope (a) and y intercept (b) tells us all.
¨ So we need to turn our data sets into straight lines.¨ This is easiest done using log-s, because they turn an
exponential into a multiplicative factor, and a multiplicative factor into a shift.
log an = n log alog a*n = log a + log n
Exponential functions
n log(2n) = n log2 linear in nlog(3n) = n log3
the log(base) of the exponential becomes the multiplicative constant and determines the slope in the plotn log(4*3n) = n log3 + log4 linear, same slope
log((3n)/4) = n log3 – log4 but *4 or /4 shiftsthe plot up or down
Exponentials: semi log plot
n 2n 3n 20*3n0 1 1 201 2 3 602 4 9 1803 8 27 5404 16 81 16205 32 243 48607 128 2087 4174010 1024 56349 1126980
1"
10"
100"
1000"
10000"
100000"
1000000"
10000000"
0" 2" 4" 6" 8" 10" 12"
2^n"
3^n"
20"3^n"
Semi log plot:y–axis on log scalex-axis linear
slope: log baseshift: multiplicative factor
Polynomialsn What if we take the log of a polynomial?
e.g. f(n) = 5n3
log(f(n)) = log(5n3) = log5 + 3 log(n)not a straight line!
n But the log of a polynomial is linear in log(n)n Therefore we need to plot polynomials on a
log log scale (both x and y axis logarithmic)
Polynomials: log-log plot
n n2 n3 20*n31 1 1 202 4 8 1604 16 64 12808 64 512 1024016 256 4096 8182032 1024 32768 655360
slope: degreeshift: multiplicative factor
1"
10"
100"
1000"
10000"
100000"
1000000"
1" 10" 100"
n^2"
n^3"
20"n^3"
ExamplePlot data:1,642,1283,2564,5125,10246,20487,40968,8192
linear linear log log
semi log
Semi log plot makes a straight line
Example continuedPlot data:1,642,1283,2564,5125,10246,20487,40968,8192
semi log
Semi log plot makes a straight line.Therefore we have exponential data.
slope: (13-6)/(8-1)=1
log2 base = 1, thereforebase = 2log base = 21 = 2