Reduce function call and attribute lookup overhead when translating arcs
to segments. This gains a few seconds on 9000 arcs according to
cProfile.
---
On Thu, Mar 11, 2010 at 07:10:07PM -0600, Jeff Epler wrote:
> In some changes I haven't shown yet, I found a nice speed bump from
> gathering up all the segments on an arc in a list, and passing them in a
> single call to a new method 'straight_arcsegments'.
Here it is. I didn't make sure that it applies on top of master (I've
got about 17 other commits locally) but it should give the flavor of the
idea even if it doesn't apply.
lib/python/rs274/glcanon.py | 14 ++++++++++----
lib/python/rs274/interpret.py | 7 +++++--
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/lib/python/rs274/glcanon.py b/lib/python/rs274/glcanon.py
index bef38f5..96b990b 100644
--- a/lib/python/rs274/glcanon.py
+++ b/lib/python/rs274/glcanon.py
@@ -134,11 +134,17 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
finally:
self.in_arc = False
- def straight_arcsegment(self, x,y,z, a,b,c, u, v, w):
+ def straight_arcsegments(self, segs):
self.first_move = False
- l = (x,y,z,a,b,c,u,v,w)
- self.arcfeed_append((self.lineno, self.lo, l, self.feedrate, [self.xo,
self.yo, self.zo]))
- self.lo = l
+ lo = self.lo
+ lineno = self.lineno
+ feedrate = self.feedrate
+ to = [self.xo, self.yo, self.zo]
+ append = self.arcfeed_append
+ for l in segs:
+ append((lineno, lo, l, feedrate, to))
+ lo = l
+ self.lo = lo
def straight_feed(self, x,y,z, a,b,c, u, v, w):
if self.suppress > 0: return
diff --git a/lib/python/rs274/interpret.py b/lib/python/rs274/interpret.py
index 6229bbc..5646f5e 100644
--- a/lib/python/rs274/interpret.py
+++ b/lib/python/rs274/interpret.py
@@ -96,6 +96,8 @@ class ArcsToSegmentsMixin:
def interp(low, high):
return low + (high-low) * i / steps
+ segs = []
+ seg_append = segs.append
steps = max(8, int(128 * abs(theta1 - theta2) / math.pi))
p = [0] * 9
for i in range(1, steps):
@@ -110,8 +112,9 @@ class ArcsToSegmentsMixin:
p[6] = interp(o[6], n[6])
p[7] = interp(o[7], n[7])
p[8] = interp(o[8], n[8])
- self.straight_arcsegment(*p)
- self.straight_arcsegment(*n)
+ seg_append(tuple(p))
+ seg_append(tuple(n));
+ self.straight_arcsegments(segs)
class PrintCanon:
def set_origin_offsets(self, *args):
--
1.6.3.3
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers