Skip to content

Instantly share code, notes, and snippets.

View smerritt's full-sized avatar

Sam Merritt smerritt

View GitHub Profile
@smerritt
smerritt / jsonbench.py
Created July 25, 2013 21:13
benchmarking various python json libraries
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
#
# Benchmark the relative performance of stdlib's json, simplejson, ujson, and
# a wrapped simplejson that gives the same API as stdlib's json.
import benchmark
import hashlib
import json as stdjson
import simplejson
@smerritt
smerritt / pre-commit.py
Created August 30, 2013 20:01
pre-commit hook I use to prevent trailing commas in JSON test files
#!/usr/bin/env python
import sys
import os.path
import subprocess
import tempfile
import re
import json
import shutil
import atexit
#!/usr/bin/env python
#
# Make some big rings for testing. Doesn't do command-line arg parsing or
# anything fancy; just go change the hard-coded constants. It's not like
# you're going to run this more than a few times before tossing it out.
import os
import subprocess
# clean up from previous runs, if any
@smerritt
smerritt / flake8-check
Created September 17, 2013 21:46
Pre-commit hooks for python development
#!/usr/bin/env python
#
# flake8-checks the staged versions of any changed python files
import os.path
import subprocess
import tempfile
import shutil
import atexit
tempdir = tempfile.mkdtemp()
#!/usr/bin/env python
import benchmark
import Queue
import threading
import os
class BenchQueueStuff(benchmark.Benchmark):
def setUp(self):
@smerritt
smerritt / results
Created September 19, 2013 20:06
bench more queue stuff, now with differences between sleeps and full queues
#!/usr/bin/env python
import benchmark
import Queue
import os
import subprocess
import tempfile
import time
import threading
@smerritt
smerritt / gist:7605771
Last active June 17, 2017 21:23
OpenStack Swift code review checklist
* Are there tests? Do the new tests fail if the code is reverted?
* Does it work? There's no such thing as obviously correct, as I've had to learn again and again.
* Check the coverage report; is any new code uncovered? (This might be okay, but take a look.)
* How's the logging?
* Read all the tests; any leftover debugging cruft? Print statements seem particularly common.
#!/usr/bin/env python
import os
from swift.common.utils import get_logger
NLOGGERS = 500
for _ in xrange(NLOGGERS):
get_logger({})
#!/usr/bin/env python
import benchmark
import heapq
class BenchHeapq(benchmark.Benchmark):
def eachSetUp(self):
self.size = 500
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Benchmark the relative performance of stdlib's json, simplejson, and
# a wrapped simplejson that gives the same API as stdlib's json.
import benchmark
import hashlib
import json as stdjson
import simplejson