Skip to content

Instantly share code, notes, and snippets.

@ipmb
Last active September 27, 2020 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ipmb/5041009 to your computer and use it in GitHub Desktop.
Save ipmb/5041009 to your computer and use it in GitHub Desktop.
Test speeds of different Django password hashing functions
#!/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