-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_versus_tuple.py
More file actions
44 lines (28 loc) · 1.03 KB
/
Copy pathlist_versus_tuple.py
File metadata and controls
44 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
# pylint: disable=C0103
"""Compare tuple performance versus list performance."""
import gc
import benchmark
class Benchmark_Tuple(benchmark.Benchmark):
"""Benchmark tuple allocation."""
each = 100 # allows for differing number of runs
def setUp(self):
"""Define the number of benchmarks to perform."""
self.size = 25000
def test_tuple(self):
"""Allocate the specified number of tuples."""
for _ in xrange(self.size):
_ = (j for j in xrange(1, 100))
class Benchmark_List(benchmark.Benchmark):
"""Benchmark list allocation."""
each = 100 # allows for differing number of runs
def setUp(self):
"""Define the number of benchmarks to perform."""
self.size = 25000
def test_list(self):
"""Allocate the specified number of lists."""
for _ in xrange(self.size):
_ = [j for j in xrange(1, 100)]
if __name__ == '__main__':
gc.disable()
benchmark.main(each=500, format="markdown", numberFormat="%.4g")