tests: Format all Python code with black, except tests in basics subdir.

This adds the Python files in the tests/ directory to be formatted with
./tools/codeformat.py.  The basics/ subdirectory is excluded for now so we
aren't changing too much at once.

In a few places `# fmt: off`/`# fmt: on` was used where the code had
special formatting for readability or where the test was actually testing
the specific formatting.
This commit is contained in:
David Lechner
2020-03-22 21:26:08 -05:00
committed by Damien George
parent 488613bca6
commit 3dc324d3f1
472 changed files with 4396 additions and 2891 deletions

View File

@@ -3,10 +3,12 @@
# method is that it doesn't require any extra memory allocation.
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
arr = [0] * 1000
for i in range(len(arr)):
arr[i] += 1
bench.run(test)

View File

@@ -4,9 +4,11 @@
# array). On the other hand, input array stays intact.
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
arr = [0] * 1000
arr2 = list(map(lambda x: x + 1, arr))
bench.run(test)

View File

@@ -3,10 +3,12 @@
# method is that it doesn't require any extra memory allocation.
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
arr = bytearray(b"\0" * 1000)
for i in range(len(arr)):
arr[i] += 1
bench.run(test)

View File

@@ -4,9 +4,11 @@
# array). On the other hand, input array stays intact.
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
arr = bytearray(b"\0" * 1000)
arr2 = bytearray(map(lambda x: x + 1, arr))
bench.run(test)

View File

@@ -3,6 +3,7 @@ import time
ITERS = 20000000
def run(f):
t = time.time()
f(ITERS)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
for i in iter(range(num // 1000)):
bytes(10000)
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
for i in iter(range(num // 1000)):
b"\0" * 10000
bench.run(test)

View File

@@ -2,10 +2,12 @@
# Inplace - the most memory efficient way
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
for i in range(len(ba)):
ba[i] += 1
bench.run(test)

View File

@@ -4,9 +4,11 @@
# this is slowest way to do it.
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = b''.join(map(lambda x:bytes([x + 1]), ba))
ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))
bench.run(test)

View File

@@ -2,9 +2,11 @@
# No joins, but still map().
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = list(l)
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = list(map(lambda x: x, l))
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = tuple(l)
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = tuple(map(lambda x: x, l))
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = bytes(l)
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = bytes(map(lambda x: x, l))
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = bytearray(l)
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
for i in iter(range(num//10000)):
for i in iter(range(num // 10000)):
l = [0] * 1000
l2 = bytearray(map(lambda x: x, l))
bench.run(test)

View File

@@ -1,10 +1,13 @@
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
func(i)
bench.run(test)

View File

@@ -1,10 +1,13 @@
import bench
def func(a, b, c):
pass
def test(num):
for i in iter(range(num)):
func(i, i, i)
bench.run(test)

View File

@@ -1,10 +1,13 @@
import bench
def func(a, b=1, c=2):
pass
def test(num):
for i in iter(range(num)):
func(i)
bench.run(test)

View File

@@ -1,10 +1,13 @@
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
func(a=i)
bench.run(test)

View File

@@ -1,10 +1,13 @@
import bench
def func(a, b, c):
pass
def test(num):
for i in iter(range(num)):
func(c=i, b=i, a=i)
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
for i in iter(range(num//20)):
for i in iter(range(num // 20)):
enumerate([1, 2], 1)
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
for i in iter(range(num//20)):
for i in iter(range(num // 20)):
enumerate(iterable=[1, 2], start=1)
bench.run(test)

View File

@@ -2,8 +2,10 @@
# Establish a baseline for performing a trivial operation inline
import bench
def test(num):
for i in iter(range(num)):
a = i + 1
bench.run(test)

View File

@@ -2,11 +2,14 @@
# Perform the same trivial operation as global function call
import bench
def f(x):
return x + 1
def test(num):
for i in iter(range(num)):
a = f(i)
bench.run(test)

View File

@@ -5,12 +5,15 @@
# variables are accessed by offset, not by name)
import bench
def f(x):
return x + 1
def test(num):
f_ = f
for i in iter(range(num)):
a = f_(i)
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
for i in range(num):
pass
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
for i in iter(range(num)):
pass
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
i = 0
while i < num:
i += 1
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
while num > 0:
num -= 1
bench.run(test)

View File

@@ -1,7 +1,9 @@
import bench
def test(num):
while num != 0:
num -= 1
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
zero = 0
while num != zero:
num -= 1
bench.run(test)

View File

@@ -1,8 +1,10 @@
import bench
def test(num):
i = 0
while i < 20000000:
i += 1
bench.run(test)

View File

@@ -2,9 +2,11 @@ import bench
ITERS = 20000000
def test(num):
i = 0
while i < ITERS:
i += 1
bench.run(test)

View File

@@ -7,4 +7,5 @@ def test(num):
while i < ITERS:
i += 1
bench.run(test)

View File

@@ -6,4 +6,5 @@ def test(num):
while i < num:
i += 1
bench.run(lambda n:test(20000000))
bench.run(lambda n: test(20000000))

View File

@@ -1,11 +1,14 @@
import bench
class Foo:
num = 20000000
def test(num):
i = 0
while i < Foo.num:
i += 1
bench.run(test)

View File

@@ -1,14 +1,16 @@
import bench
class Foo:
class Foo:
def __init__(self):
self.num = 20000000
def test(num):
o = Foo()
i = 0
while i < o.num:
i += 1
bench.run(test)

View File

@@ -1,7 +1,7 @@
import bench
class Foo:
class Foo:
def __init__(self):
self.num1 = 0
self.num2 = 0
@@ -9,10 +9,12 @@ class Foo:
self.num4 = 0
self.num = 20000000
def test(num):
o = Foo()
i = 0
while i < o.num:
i += 1
bench.run(test)

View File

@@ -1,17 +1,19 @@
import bench
class Foo:
class Foo:
def __init__(self):
self._num = 20000000
def num(self):
return self._num
def test(num):
o = Foo()
i = 0
while i < o.num():
i += 1
bench.run(test)

View File

@@ -3,10 +3,12 @@ from ucollections import namedtuple
T = namedtuple("Tup", ["num", "bar"])
def test(num):
t = T(20000000, 0)
i = 0
while i < t.num:
i += 1
bench.run(test)

View File

@@ -3,10 +3,12 @@ from ucollections import namedtuple
T = namedtuple("Tup", ["foo1", "foo2", "foo3", "foo4", "num"])
def test(num):
t = T(0, 0, 0, 0, 20000000)
i = 0
while i < t.num:
i += 1
bench.run(test)