- L1 cache reference
0.5 ns
- Branch mispredict
5 ns
(on a bad CPU architecture you're pretty much screwed) - L2 cache reference
7 ns
- Mutex lock/unlock
25 ns
- Main memory reference
100 ns
- Compress 1K bytes with Zippy
3,000 ns
- Send 2K bytes over 1 Gbps network
20,000 ns
- Read 1 MB sequentially from memory
250,000 ns
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
class ExtendedEmbeddedDocumentField(BaseField): | |
"""An embedded document field attaches the owner_document to field, | |
when pulled from the database. | |
""" | |
def to_python(self, value): | |
if not isinstance(value, self.document_type): | |
embedded = self.document_type._from_son(value) |
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
import datetime | |
import simplejson | |
from pymongo.dbref import DBRef | |
from pymongo.objectid import ObjectId | |
class MongoEngineEncoder(simplejson.JSONEncoder): | |
"""Handles Encoding of ObjectId's""" |
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
import fabric | |
from fabric.api import env | |
from functools import wraps | |
############################################################################### | |
# Decorators | |
############################################################################### | |
def limit_roles(*role_list): |
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
from flask import Flask | |
from flask.ext.mongoengine import MongoEngine | |
app = Flask(__name__) | |
app.config.from_pyfile('the-config.cfg') | |
db = MongoEngine(app) # Pass the app | |
db.init_app(app) # Initiate the app |
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
[ | |
{ | |
"id": "edit", | |
"children": | |
[ | |
{ | |
"id": "sublime_highlight", | |
"caption": "Highlight", | |
"children": | |
[ |
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
import unittest | |
from datetime import datetime | |
from mongoengine import * | |
from mongoengine.queryset import QuerySet | |
class BugFixTest(unittest.TestCase): | |
def setUp(self): |
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
from mongoengine import * | |
import objgraph | |
import random | |
import inspect | |
def main(): | |
""" | |
Run by calling: python leak.py |
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
import unittest | |
from mongoengine import * | |
class Test(unittest.TestCase): | |
def setUp(self): | |
conn = connect(db='mongoenginetest') | |
def create_old_data(self): |
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
import unittest | |
from mongoengine import * | |
from mongoengine.tests import query_counter | |
class Test(unittest.TestCase): | |
def setUp(self): | |
conn = connect(db='mongoenginetest') |