Last active
April 15, 2020 23:53
-
-
Save mikebridge/dcbd7a679728a28eaf7ca8170d75c73a to your computer and use it in GitHub Desktop.
django-simple-history test
This file contains hidden or 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
from decimal import Decimal | |
from functools import reduce | |
from django.db import connection, reset_queries | |
from apps.accounts.models import User | |
me = User.objects.get(email='[email protected]') | |
iterations = 1000 | |
def test_save(iterations1 = 1000): | |
reset_queries() | |
for i in range(iterations1): | |
me.first_name="Test {}".format(i) | |
me.save() | |
total_time = reduce(lambda x, y: x+y, [Decimal(x["time"]) for x in connection.queries]) | |
reset_queries() | |
return total_time / iterations1 | |
print (f"current revisions: { me.history.count()}") | |
average_query_time_with_revisions = test_save(iterations) | |
print(f"saving with revisions took {average_query_time_with_revisions}") | |
me.skip_history_when_saving = True | |
print (f"current revisions: { me.history.count()}") | |
average_query_time_without_revisions = test_save(iterations) | |
print(f"saving without revisions took {average_query_time_without_revisions}") | |
print (f"current revisions: { me.history.count()}") | |
print((average_query_time_without_revisions - average_query_time_with_revisions) / average_query_time_without_revisions) | |
del me.skip_history_when_saving |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment