CS320: Performance Evaluation Plotting data sets Semi-log plots Log-log plots
Analyzing Program Performance In Computer Science, we plot functions describing the run time (or the memory use) of a program a s 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(n 2 ) or O(2 n ) 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 180" n f(n) g(n) h(n) 160" 1 2 9 2 140" 2 12 18 6 120" 3 36 35 24 100" f" 4 80 68 68 g" 80" 5 150 131 162 h" 60" What kinds of functions are 40" f, g and h? 20" exponential? which base? • 0" polynomial? which order? 1" 2" 3" 4" 5" • Hard / impossible to infer 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 18000" n f(n) g(n) h(n) 16000" 2 9 2 1 14000" 12 18 6 2 12000" 36 35 24 3 10000" f" 80 68 68 4 g" 8000" 5 150 131 162 h" 6000" 400 520 624 7 4000" 1100 4106 2510 10 2000" 1872 16396 5196 12 0" 0" 2" 4" 6" 8" 10" 12" 14" Do you get a better idea now? Which function may be polynomial, which exponential? Still, not all clear (order, base…), h(n) may spike up later… The steeper a plot, the higher its Order of Magnitude.
Straight Lines We 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 a multiplicative factor into a shift (y axis crossing b) , and an exponential into a multiplicative factor (slope a)
Exponential functions n log(2 n ) = n log2 linear in n n log(3 n ) = n log3 the log factor determines angle n log(4.3 n ) = n log3 + log4 * 4 shifts up n log((3 n )/4) = n log3 – log4 / 4 shifts down
Exponentials: semi-log plot n 2 n 3 n 20*3 n 10000000" 0 1 1 20 1000000" 1 2 3 60 2 4 9 180 100000" 3 8 27 540 10000" 2^n" 4 16 81 1620 3^n" 5 32 243 4860 1000" 20"3^n" 7 128 2087 41740 100" 10 1024 56349 1126980 10" semi-log plot: y–axis on log scale 1" x-axis linear 0" 2" 4" 6" 8" 10" 12" angle: base shift: multiplicative factor
Polynomials n What if we take the log of a polynomial? e.g. f(n) = 5n 3 log(f(n)) = log(5n 3 ) = 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 n 2 n 3 20*n 3 1000000" 1 1 1 20 100000" 2 4 8 160 4 16 64 1280 10000" 8 64 512 10240 n^2" 16 256 4096 81820 1000" n^3" 32 1024 32768 655360 20"n^3" 100" angle: degree 10" shift: multiplicative factor 1" 1" 10" 100"
Recommend
More recommend