2022.10.9 - Enumerable & List (#105) #106
@ -5,8 +5,8 @@ import unittest
|
|||||||
from cpl_query.enumerable import Enumerable
|
from cpl_query.enumerable import Enumerable
|
||||||
from cpl_query.iterable import Iterable
|
from cpl_query.iterable import Iterable
|
||||||
|
|
||||||
VALUES = 10000
|
VALUES = 1000
|
||||||
COUNT = 50
|
COUNT = 75
|
||||||
|
|
||||||
|
|
||||||
class PerformanceTestCase(unittest.TestCase):
|
class PerformanceTestCase(unittest.TestCase):
|
||||||
@ -24,9 +24,9 @@ class PerformanceTestCase(unittest.TestCase):
|
|||||||
iterable = timeit.timeit(lambda: Iterable(int, self.values), number=COUNT)
|
iterable = timeit.timeit(lambda: Iterable(int, self.values), number=COUNT)
|
||||||
|
|
||||||
print('Range')
|
print('Range')
|
||||||
print(f'd: {default}')
|
print(f'd: {default}s')
|
||||||
print(f'i: {iterable}')
|
print(f'i: {iterable}s')
|
||||||
print(f'e: {enumerable}')
|
print(f'e: {enumerable}s')
|
||||||
|
|
||||||
self.assertLess(default, enumerable)
|
self.assertLess(default, enumerable)
|
||||||
self.assertLess(default, iterable)
|
self.assertLess(default, iterable)
|
||||||
@ -37,9 +37,32 @@ class PerformanceTestCase(unittest.TestCase):
|
|||||||
enumerable = timeit.timeit(lambda: Enumerable(int, self.values).where(lambda x: x == 50).single(), number=COUNT)
|
enumerable = timeit.timeit(lambda: Enumerable(int, self.values).where(lambda x: x == 50).single(), number=COUNT)
|
||||||
|
|
||||||
print('Where single')
|
print('Where single')
|
||||||
print(f'd: {default}')
|
print(f'd: {default}s')
|
||||||
print(f'i: {iterable}')
|
print(f'i: {iterable}s')
|
||||||
print(f'e: {enumerable}')
|
print(f'e: {enumerable}s')
|
||||||
|
|
||||||
|
self.assertLess(default, enumerable)
|
||||||
|
self.assertLess(default, iterable)
|
||||||
|
|
||||||
|
def test_where_single_complex(self):
|
||||||
|
class TestModel:
|
||||||
|
|
||||||
|
def __init__(self, v, tm=None):
|
||||||
|
self.value = v
|
||||||
|
self.tm = tm
|
||||||
|
|
||||||
|
values = []
|
||||||
|
for i in range(VALUES):
|
||||||
|
values.append(TestModel(i, TestModel(i + 1)))
|
||||||
|
|
||||||
|
default = timeit.timeit(lambda: [x for x in list(values) if x.tm.value == 50], number=COUNT)
|
||||||
|
iterable = timeit.timeit(lambda: Iterable(TestModel, values).where(lambda x: x.tm.value == 50).single(), number=COUNT)
|
||||||
|
enumerable = timeit.timeit(lambda: Enumerable(TestModel, values).where(lambda x: x.tm.value == 50).single(), number=COUNT)
|
||||||
|
|
||||||
|
print('Complex where single')
|
||||||
|
print(f'd: {default}s')
|
||||||
|
print(f'i: {iterable}s')
|
||||||
|
print(f'e: {enumerable}s')
|
||||||
|
|
||||||
self.assertLess(default, enumerable)
|
self.assertLess(default, enumerable)
|
||||||
self.assertLess(default, iterable)
|
self.assertLess(default, iterable)
|
||||||
|
Loading…
Reference in New Issue
Block a user