Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting a LocalizedValue to string seems slow #45

Open
bogdanhopu opened this issue Feb 16, 2018 · 0 comments
Open

Casting a LocalizedValue to string seems slow #45

bogdanhopu opened this issue Feb 16, 2018 · 0 comments
Labels

Comments

@bogdanhopu
Copy link
Contributor

bogdanhopu commented Feb 16, 2018

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                                                       }
@bogdanhopu bogdanhopu added the bug label Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant