Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96113
License: OTHER
1
""" Example code for Think OS.
2
3
This program plots results from cache.c
4
5
To use it:
6
7
gcc -o cache cache.c
8
./cache > cache_data
9
python graph_data.py
10
11
It depends on thinkplot.py and matplotlib
12
13
Copyright 2014 Allen Downey
14
License: GNU GPLv3
15
16
"""
17
18
import thinkplot
19
import matplotlib.pyplot as pyplot
20
21
d = {}
22
for line in open('cache_data'):
23
t = line.split()
24
size, stride, time = int(t[1]), int(t[3]), float(t[5])
25
d.setdefault(stride, []).append((size, time))
26
27
28
thinkplot.PrePlot(num=7)
29
for stride in reversed(sorted(d.keys())):
30
xs, ys = zip(*d[stride])
31
thinkplot.plot(xs, ys, label=str(stride)+' B')
32
33
pyplot.xscale('log', basex=2)
34
thinkplot.save(root='cache_data',
35
xlabel='size (B)',
36
ylabel='average penalty (ns)')
37
38