update
This commit is contained in:
27
engine/tests/fixtures/demo_sort.py
vendored
Normal file
27
engine/tests/fixtures/demo_sort.py
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Demo script for users: contains several detectable anti-patterns.
|
||||
|
||||
- membership test against a list inside a loop -> membership_in_list
|
||||
- nested loops -> nested_loops
|
||||
- string concatenation with += inside a loop -> str_concat_loop
|
||||
"""
|
||||
|
||||
|
||||
def build_report(rows, allow):
|
||||
out = ""
|
||||
for r in rows:
|
||||
if r in allow: # O(n) membership test on a list
|
||||
out += str(r) + "," # string += accumulation
|
||||
for other in rows: # nested loop -> O(n^2)
|
||||
if r == other:
|
||||
pass
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
rows = list(range(400))
|
||||
allow = list(range(0, 400, 2))
|
||||
for _ in range(30):
|
||||
build_report(rows, allow)
|
||||
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user