Casting a LocalizedValue to string seems slow
bogdanhopu opened this issue · 0 comments
bogdanhopu commented
Here are some benchmarks comparing the LocalizeValue
with accessing a dict
element:
Line # Hits Time Per Hit % Time Line Contents
280 112864 2373159.0 21.0 43.4 'location': {'slug': str(location.slug), 'name': str(location.name)},
280 112864 145854.0 1.3 4.3 'location': {'slug': location.slug[lang], 'name': location.name[lang]},
Line # Hits Time Per Hit % Time Line Contents
==============================================================
279 result = {
280 112864 2373159.0 21.0 43.4 'location': {'slug': str(location.slug), 'name': str(location.name)},
281 112864 95490.0 0.8 1.7 'purpose': purpose
282 }
283 112864 72180.0 0.6 1.3 if category:
284 result['category'] = {
285 109312 1198026.0 11.0 21.9 'slug': str(self.categories[category]['slug']),
286 109312 1122646.0 10.3 20.6 'name': str(self.categories[category]['name'])
287 }
Line # Hits Time Per Hit % Time Line Contents
==============================================================
278 112864 369103.0 3.3 10.9 lang = django.utils.translation.get_language()
279 result = {
280 112864 145854.0 1.3 4.3 'location': {'slug': location.slug[lang], 'name': location.name[lang]},
281 112864 93499.0 0.8 2.8 'purpose': purpose
282 }
283 112864 73027.0 0.6 2.2 if category:
284 result['category'] = {
285 109312 1298347.0 11.9 38.3 'slug': str(self.categories[category]['slug']),
286 109312 1162843.0 10.6 34.3 'name': str(self.categories[category]['name'])
287 }