Created
May 10, 2012 23:34
-
-
Save etianen/2656581 to your computer and use it in GitHub Desktop.
benchmark.py
This file contains 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 | |
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