Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This can be used to find faster ways to perform tasks in RoboFont using python
import time
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw:
name = kw.get('log_name', method.__name__.upper())
kw['log_time'][name] = int((te - ts) * 1000)
else:
print('%r %2.2f ms' %(method.__name__, (te - ts) * 1000))
return result
return timed
f = CurrentFont()
# -----------------------------------------------------------------------------
# 1. Check if glyph is in a font
@timeit
def testGlyphInFont(f):
for i in range(1000):
'a' in f
glyphSet = set(f.keys())
@timeit
def testGlyphInSet(glyphSet):
for i in range(1000):
'a' in glyphSet
testGlyphInFont(f)
testGlyphInSet(glyphSet)
# Result: Using a set is a lot faster than using Font for checking if a glyph exist
# -----------------------------------------------------------------------------
# 1. Check index of a glyph name in glyphOrder
@timeit
def testFontGlyphOrder(f):
for i in range(100):
f.glyphOrder.index('a')
glyphOrder = f.glyphOrder[:]
@timeit
def testListGlyphOrder(glyphOrder):
for i in range(100):
glyphOrder.index('a')
testFontGlyphOrder(f)
testListGlyphOrder(glyphOrder)
# Result: Using a list is a lot faster than using Font for checking index of a glyph in glyphOrder
# -----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.