Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Using PyYaml with libyaml installed makes a huge difference in speed
from __future__ import with_statement
import yaml
import time
class Timer(object):
def __enter__(self):
self.__start = time.time()
def __exit__(self, type, value, traceback):
# Error handling here
self.__finish = time.time()
def duration_in_seconds(self):
return self.__finish - self.__start
timer = Timer()
with timer:
with open('fixtures/migrated_tender.yaml') as f:
document = f.read()
doc = yaml.load(document, Loader=yaml.CLoader)
print timer.duration_in_seconds()
from __future__ import with_statement
import yaml
import time
class Timer(object):
def __enter__(self):
self.__start = time.time()
def __exit__(self, type, value, traceback):
# Error handling here
self.__finish = time.time()
def duration_in_seconds(self):
return self.__finish - self.__start
timer = Timer()
with timer:
with open('fixtures/migrated_tender.yaml') as f:
document = f.read()
doc = yaml.load(document, Loader=yaml.Loader)
print timer.duration_in_seconds()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment