-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from alfred82santa/feature/performance-tests
Added performace test, BlobField and slots for models
- Loading branch information
Showing
7 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dirtymodels@0.3.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from datetime import datetime, timedelta | ||
from sys import setrecursionlimit | ||
from functools import reduce | ||
|
||
|
||
class Runner: | ||
|
||
def __init__(self, config): | ||
self.config = config | ||
|
||
def run(self): | ||
setrecursionlimit(9999999) | ||
|
||
result = {} | ||
for label, data in self.config.items(): | ||
test = data['test_class'](**data['params']) | ||
test.prepare() | ||
result_test = [] | ||
print ('{0} start'.format(label)) | ||
for i in range(data.get('repeats', 1)): | ||
print ('{0}: iteration no. {1} start'.format(label, i)) | ||
time_start = datetime.now() | ||
test.run() | ||
time_stop = datetime.now() | ||
elapsed = time_stop - time_start | ||
print ('{0}: iteration no. {1} => {2}'.format(label, i, str(elapsed))) | ||
result_test.append(elapsed) | ||
total = reduce(lambda acc, x: acc + x, result_test, timedelta()) | ||
print ('{0} => {1}'.format(label, str(total))) | ||
result[label] = {'results': result_test, 'total': total} | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
''' | ||
Created on 15/09/2014 | ||
:author: alfred | ||
''' | ||
from dirty_models.models import BaseModel | ||
from dirty_models.fields import BlobField | ||
from performance.dynamicmodel import create_dict | ||
|
||
|
||
class FakeDynModel(BaseModel): | ||
fake_data = BlobField() | ||
|
||
|
||
class BlobFieldPerformance: | ||
|
||
def __init__(self, depth=5, children_count=5): | ||
self.depth = depth | ||
self.children_count = children_count | ||
|
||
def prepare(self): | ||
self.data = create_dict(self.depth, self.children_count) | ||
|
||
def run(self): | ||
return FakeDynModel(data={'fake_data': self.data}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
''' | ||
Created on 15/09/2014 | ||
:author: alfred | ||
''' | ||
from dirty_models.models import DynamicModel, BaseModel | ||
from dirty_models.fields import ModelField | ||
|
||
|
||
def create_dict(depth=5, children_count=5): | ||
if depth > 0: | ||
return {'test_{0}'.format(i): create_dict(depth - 1, children_count) for i in range(children_count)} | ||
else: | ||
return 'top' | ||
|
||
|
||
class FakeDynModel(BaseModel): | ||
fake_data = ModelField(model_class=DynamicModel) | ||
|
||
|
||
class DynamicModelPerformance: | ||
|
||
def __init__(self, depth=5, children_count=5): | ||
self.depth = depth | ||
self.children_count = children_count | ||
|
||
def prepare(self): | ||
self.data = create_dict(self.depth, self.children_count) | ||
|
||
def run(self): | ||
return FakeDynModel(data={'fake_data': self.data}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
''' | ||
Created on 15/09/2014 | ||
:author: alfred | ||
''' | ||
from performance import Runner | ||
from performance.dynamicmodel import DynamicModelPerformance | ||
from performance.blobfield import BlobFieldPerformance | ||
|
||
config = {'DynamicModel': {'test_class': DynamicModelPerformance, | ||
'repeats': 5, | ||
'params': {'depth': 6, 'children_count': 6}}, | ||
'BlobField': {'test_class': BlobFieldPerformance, | ||
'repeats': 5, | ||
'params': {'depth': 6, 'children_count': 6}}} | ||
|
||
if __name__ == '__main__': | ||
|
||
runner = Runner(config) | ||
|
||
print(runner.run()) |