Skip to content

Instantly share code, notes, and snippets.

@etianen
Created May 10, 2012 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etianen/2656581 to your computer and use it in GitHub Desktop.
Save etianen/2656581 to your computer and use it in GitHub Desktop.
benchmark.py
import timeit
from django.utils.html import escape, escapejs
def main():
test_text = u'This is just some plain old text'
test_html = u'<a href="http://www.example.com">http://www.example.com/</a>'
def test_escape_text():
escape(test_text)
def test_escape_html():
escape(test_html)
def test_escapejs_text():
escapejs(test_text)
def test_escapejs_html():
escapejs(test_html)
print "escape_text :",timeit.Timer(test_escape_text).timeit(100000)
print "escape_html :",timeit.Timer(test_escape_html).timeit(100000)
print "escapejs_text :",timeit.Timer(test_escapejs_text).timeit(100000)
print "escapejs_html :",timeit.Timer(test_escapejs_html).timeit(100000)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment