-
-
Save KTZgraph/483869826f5de379c3c53ad6dbbdc781 to your computer and use it in GitHub Desktop.
Test speeds of different Django password hashing functions
This file contains hidden or 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
#!/usr/bin/env python | |
import os | |
import time | |
from django.contrib.auth.hashers import make_password | |
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') | |
class Timer(object): | |
def __init__(self, name, iterations): | |
self.name = name | |
self.iterations = iterations | |
def __enter__(self): | |
self.start = time.time() | |
def __exit__(self, *args): | |
total = time.time() - self.start | |
print "{0}: {1} iterations in {2} seconds".format(self.name, self.iterations, total) | |
def time_hasher(hasher, iterations): | |
with Timer(hasher): | |
for i in range(iterations): | |
make_password('password', hasher=hasher) | |
time_hasher('sha1', 1000) | |
time_hasher('pbkdf2_sha256', 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment