Created
November 7, 2013 03:20
-
-
Save jacobh/7348419 to your computer and use it in GitHub Desktop.
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
import timeit | |
setup = ''' | |
from proposals.models import Proposal | |
from proposals.serializers import ProposalSerializer | |
from rest_framework.renderers import JSONRenderer | |
from drf_ujson.renderers import UJSONRenderer | |
proposals = list(Proposal.objects.all().prefetch_related( | |
'media_items', | |
'images', | |
'article__media_items', | |
'article__images', | |
).select_related( | |
'created_by', | |
'assigned_by', | |
'assigned_to', | |
'accepted_by', | |
'status_by', | |
'section', | |
'article', | |
'followers', | |
)) | |
serialized = ProposalSerializer(proposals, many=True).data | |
''' | |
stdlib_test = ''' | |
JSONRenderer().render(serialized) | |
''' | |
ujson_test = ''' | |
UJSONRenderer().render(serialized) | |
''' | |
stdlib_result = timeit.repeat(stdlib_test, setup=setup, number=1, repeat=10) | |
ujson_result = timeit.repeat(ujson_test, setup=setup, number=1, repeat=10) | |
print stdlib_result | |
print sum(stdlib_result) / 10 | |
print ujson_result | |
print sum(ujson_result) / 10 |
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
# stdlib results | |
[ | |
0.004502058029174805, | |
0.004289865493774414, | |
0.006896018981933594, | |
0.0048198699951171875, | |
0.004084110260009766, | |
0.007154941558837891, | |
0.003937959671020508, | |
0.004029035568237305, | |
0.004770040512084961, | |
0.004539966583251953 | |
] | |
# avg | |
0.00490238666534 | |
# ujson results | |
[ | |
0.0016620159149169922, | |
0.001817941665649414, | |
0.0015261173248291016, | |
0.0040950775146484375, | |
0.0021469593048095703, | |
0.001798868179321289, | |
0.001569986343383789, | |
0.0019931793212890625, | |
0.0017120838165283203, | |
0.001814126968383789 | |
] | |
# avg | |
0.00201363563538 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment