#37088: path based MediaAsset equality
-------------------------------------+-------------------------------------
     Reporter:  Johannes Maron       |                    Owner:  Johannes
                                     |  Maron
         Type:  Bug                  |                   Status:  assigned
    Component:  Forms                |                  Version:  6.0
     Severity:  Normal               |               Resolution:
     Keywords:  Media MediaAsset     |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Johannes Maron):

 I used the following script to benchmark:


 {{{
 import timeit

 from django.forms.widgets import Script, Stylesheet

 # Setup: create instances to compare
 setup = """
 import os
 os.environ.setdefault("DJANGO_SETTINGS_MODULE",
 "tests.staticfiles_tests.settings")

 import django
 django.setup()
 from django.forms.widgets import Script, Stylesheet

 s1 = Script("vendor/jquery.js")
 s2 = Script("vendor/jquery.js")
 s3 = Script("vendor/other.js")

 ss1 = Stylesheet("vendor/style.css")
 ss2 = Stylesheet("vendor/style.css")
 ss3 = Stylesheet("vendor/other.css")
 """

 benchmarks = {
     "Script equal (same path)":         "s1 == s2",
     "Script not equal (diff path)":     "s1 == s3",
     "Script equal to str":              "s1 == 'vendor/jquery.js'",
     "Script not equal to str":          "s1 == 'vendor/other.js'",
     "Stylesheet equal (same path)":     "ss1 == ss2",
     "Stylesheet not equal (diff path)": "ss1 == ss3",
     "Stylesheet equal to str":          "ss1 == 'vendor/style.css'",
     "Stylesheet not equal to str":      "ss1 == 'vendor/other.css'",
 }

 N = 1_000_000

 print(f"{'Benchmark':<40} {'Total (s)':>10} {'Per call (ns)':>14}")
 print("-" * 66)
 for label, stmt in benchmarks.items():
     t = timeit.timeit(stmt, setup=setup, number=N)
     print(f"{label:<40} {t:>10.4f} {t / N * 1e9:>13.1f}ns")
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37088#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019e02d83c82-cf2ed864-5061-453a-9e6e-1375073cc47e-000000%40eu-central-1.amazonses.com.

Reply via email to