source: trunk/misc/simulators/bench_spans.py

Last change on this file was b856238, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-15T15:53:34Z

remove old Python2 future statements

  • Property mode set to 100644
File size: 2.9 KB
Line 
1
2"""
3To use this, get a trace file such as this one:
4
5wget http://tahoe-lafs.org/trac/tahoe-lafs/raw-attachment/ticket/1170/run-112-above28-flog-dump-sh8-on-nsziz.txt
6
7And run this command passing that trace file's name:
8
9python bench_spans.py run-112-above28-flog-dump-sh8-on-nsziz.txt
10"""
11
12from pyutil import benchutil
13
14from allmydata.util.spans import DataSpans
15
16import re, sys
17
18DUMP_S='_received spans trace .dump()'
19GET_R=re.compile('_received spans trace .get\(([0-9]*), ([0-9]*)\)')
20POP_R=re.compile('_received spans trace .pop\(([0-9]*), ([0-9]*)\)')
21REMOVE_R=re.compile('_received spans trace .remove\(([0-9]*), ([0-9]*)\)')
22GET_SPANS_S='_received spans trace .get_spans()'
23ADD_R=re.compile('_received spans trace .add\(([0-9]*), len=([0-9]*)\)')
24INIT_S='_received spans trace = DataSpans'
25
26class B(object):
27    def __init__(self, inf):
28        self.inf = inf
29
30    def init(self, N):
31        self.s = DataSpans()
32        # self.stats = {}
33
34    def run(self, N):
35        count = 0
36        inline = self.inf.readline()
37
38        while count < N and inline != '':
39            if DUMP_S in inline:
40                self.s.dump()
41                # self.stats['dump'] = self.stats.get('dump', 0) + 1
42            elif GET_SPANS_S in inline:
43                self.s.get_spans()
44                # self.stats['get_spans'] = self.stats.get('get_spans', 0) + 1
45            elif ADD_R.search(inline):
46                mo = ADD_R.search(inline)
47                start = int(mo.group(1))
48                length = int(mo.group(2))
49                self.s.add(start, 'x'*length)
50                # self.stats['add'] = self.stats.get('add', 0) + 1
51            elif GET_R.search(inline):
52                mo = GET_R.search(inline)
53                start = int(mo.group(1))
54                length = int(mo.group(2))
55                self.s.get(start, length)
56                # self.stats['get'] = self.stats.get('get', 0) + 1
57            elif REMOVE_R.search(inline):
58                mo = REMOVE_R.search(inline)
59                start = int(mo.group(1))
60                length = int(mo.group(2))
61                self.s.remove(start, length)
62                # self.stats['remove'] = self.stats.get('remove', 0) + 1
63            elif POP_R.search(inline):
64                mo = POP_R.search(inline)
65                start = int(mo.group(1))
66                length = int(mo.group(2))
67                self.s.pop(start, length)
68                # self.stats['pop'] = self.stats.get('pop', 0) + 1
69            elif INIT_S in inline:
70                pass
71            else:
72                print("Warning, didn't recognize this line: %r" % (inline,))
73            count += 1
74            inline = self.inf.readline()
75
76        # print(self.stats)
77
78benchutil.print_bench_footer(UNITS_PER_SECOND=1000000)
79print("(microseconds)")
80
81for N in [600, 6000, 60000]:
82    b = B(open(sys.argv[1], 'rU'))
83    print("%7d" % N, end=' ')
84    benchutil.rep_bench(b.run, N, b.init, UNITS_PER_SECOND=1000000)
85
Note: See TracBrowser for help on using the repository browser.