-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange_versus_xrange.py
More file actions
44 lines (28 loc) · 1.04 KB
/
range_versus_xrange.py
File metadata and controls
44 lines (28 loc) · 1.04 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 range performance versus xrange performance."""
import gc
import benchmark
class Benchmark_Range(benchmark.Benchmark):
"""Benchmark range allocation."""
each = 100 # allows for differing number of runs
def setUp(self):
"""Define the number of benchmarks to perform."""
self.size = 25000
def test_range(self):
"""Allocate the specified number of tuples."""
for _ in range(self.size):
_ = (j for j in range(1, 100))
class Benchmark_Xrange(benchmark.Benchmark):
"""Benchmark xrange allocation."""
each = 100 # allows for differing number of runs
def setUp(self):
"""Define the number of benchmarks to perform."""
self.size = 25000
def test_xrange(self):
"""Allocate the specified number of tuples."""
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")