Skip to content

Instantly share code, notes, and snippets.

View gist:5157404
jamesls / semidbmperf1
Created April 21, 2013 21:46
Semidbm performance
View semidbmperf1
Was trying to optimize sequential writes (fill_sequential benchmark). Showing:
* Current released version
* performance regression with python3 support
* Better performance with binary file format
Benchmark params:
100,000 keys, key size 16 bytes, value size 100 bytes
jamesls / gist:5704452
Last active December 18, 2015 01:29
cpython vs. pypy O(log n) vs. O(n^2)
View gist:5704452
Time taken to insert elements into the specified data structures.
Left hand column is total number of elements, right hand side is total time.
Recall skiplist insert is O(log n) in average case, binary search insert is O(n) worst case.
Skiplist insert (implemented in pure python):
10: 0.000175
jamesls /
Created September 5, 2013 03:38
Download all deps of a local python package
#!/usr/bin/env python
# Given a local checkout of a python package
# in SOURCE_DIR, this script will download all
# of its deps (transitively) into BUNDLE_DIR.
import os
import shutil
import subprocess
BUNDLE_DIR = '/tmp/bundle'
# Directory of the local package (should contain a file).
jamesls /
Last active December 24, 2015 15:29
thread stack traces make it hard to see CPU bound problems. Run the script with no args, and read the bottom comment in each stack trace (there are three threads so you'll see three stack traces). Note that despite taking almost 100% CPU, the stack traces show the worker thread sleeping.
import datetime
import time
import sys
import threading
import traceback
import subprocess
import random
def clear_screen():
jamesls /
Created November 21, 2013 00:12
OrderedDict vs. dict
from collections import OrderedDict
# This will raise a RuntimeError in python3, but will work
# in python2.
regular_dict = dict(a='a', b='c')
for i, j in regular_dict.items():
regular_dict[i + j] = j
# This will create an infinite loop and consume all memory
jamesls / sort.js
Created May 20, 2014 04:32
Javascript sort stability
View sort.js
function sortArray(n) {
var array = [];
for (var i = 1; i <= n; i++) {
array.push({key: 10, name: i.toString()});
array.sort(function(a, b) {
return a.key - b.key;
for(var j = 0; j < n; j++) {
process.stdout.write(array[j].name + " ");
jamesls / pr-check
Last active August 29, 2015 14:16
PR Check Script
View pr-check
#!/usr/bin/env python
"""Script to do an intial review of a PR.
There are many things that a core dev will look at when reviewing a pull
request. Many of these things will require the expertise of someone who is
familiar with the codebase.
There are also things that can be entirely automated.
That's the point of this script. To get all the checks that can be automated,
jamesls /
Created March 28, 2015 23:45
Asyncio and coroutines confusion
import asyncio
def coro():
return "foo"
# Writing the code without a list comp works,
# even with an asyncio.sleep(0.1).
View gist:e73d0adf20c6460369be
$ make test
go test -v ./...
? [no test files]
=== RUN TestCompliance
Best: a
--- PASS: TestCompliance (0.02s)
=== RUN TestCanLexTokens
--- PASS: TestCanLexTokens (0.00s)
=== RUN TestLexingErrors
--- PASS: TestLexingErrors (0.00s)