From f33193069cbbb8e9b3047007e3dad554b93e1e95 Mon Sep 17 00:00:00 2001 From: fawce Date: Tue, 12 Nov 2013 21:24:30 -0500 Subject: [PATCH] PERF: Remove in operator from inner loop. Ask forgiveness via exception handling instead. --- zipline/gens/tradesimulation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zipline/gens/tradesimulation.py b/zipline/gens/tradesimulation.py index 6b762f62..f3ffbb74 100644 --- a/zipline/gens/tradesimulation.py +++ b/zipline/gens/tradesimulation.py @@ -217,8 +217,10 @@ class AlgorithmSimulator(object): Update the universe with new event information. """ # Update our knowledge of this event's sid - if event.sid in self.current_data: + # rather than use if event.sid in ..., just trying + # and handling the exception is significantly faster + try: sid_data = self.current_data[event.sid] - else: + except KeyError: sid_data = self.current_data[event.sid] = SIDData() sid_data.__dict__.update(event.__dict__)