[IronPython] Performances and Profiling of ReportLab under IronPython
Curt Hagenlocher
curt at hagenlocher.org
Thu Aug 20 16:43:08 CEST 2009
Imports are specific to a ScriptEngine. When you create a new ScriptScope
through the hosting interface and run "import foo" inside of it, the
standard Python behavior applies -- if "foo" is already in sys.modules, it
won't be imported again. Instead, the name will just be added to the current
scope.
When you say "startup time" in this context -- that includes the time it
takes to import the modules?
On Thu, Aug 20, 2009 at 7:21 AM, Marco Parenzan <marco.parenzan at libero.it>wrote:
> Other results.
>
>
>
> I have hosted IPY in a test C# application in which I separate ScriptScope
> creation from execution: specifically, I create scope one time, import
> modules, and then execute, 100 times.
>
> Timings are ok:
>
>
>
> Python Startup Elapsed time: 10595
>
> Execution 0 Elapsed time: 1454ms
>
> Execution 1 Elapsed time: 55ms
>
> Execution 2 Elapsed time: 38ms
>
> Execution 3 Elapsed time: 32ms
>
> Execution 4 Elapsed time: 32ms
>
> Execution 5 Elapsed time: 35ms
>
> Execution 6 Elapsed time: 27ms
>
> Execution 7 Elapsed time: 27ms
>
> Execution 8 Elapsed time: 27ms
>
> Execution 9 Elapsed time: 25ms
>
> Execution 10 Elapsed time: 39ms
>
> …
>
> Execution 99 Elapsed time: 22ms
>
>
>
> At the moment for me is ok (waiting for a solutions, or, at least, to
> understand the 10 seconds!).
>
>
>
> Another question:. This is the code I use to create the scope:
>
>
>
> __pyEngine = Python.CreateEngine();
>
> __pyEngine.SetSearchPaths(__pySearchPaths);
>
>
>
> __pyScope = __pyEngine.CreateScope();
>
> __pyEngine.Execute("from reportlab.graphics.shapes import Drawing,
> String", __pyScope);
>
> __pyEngine.Execute("from reportlab.graphics import renderPDF",
> __pyScope);
>
>
>
>
>
> …and I use the scope to execute the subsequent code
>
>
>
> d = Drawing(100, 100)
>
> s = String(50, 50, "Hello World", textAlign='middle')
>
>
>
> d.add(s)
>
>
>
> renderPDF.drawToFile(d, "HelloWorld.pdf", "HW")
>
>
>
> The thing I dislike is sharing the single scope among the multiple
> execution of scripts during process life: I’d like to recreate scope every
> time, but at the moment I have the discussed module load cost. Is there any
> way to load the module at engine level (a sort of global) that all scopes
> can view, without importing every time?
>
>
>
> Thanks in advance
>
>
>
> Marco [dot] Parenzan [at] libero [dot] it
>
>
>
> *From:* Marco Parenzan [mailto:marco.parenzan at libero.it]
> *Sent:* giovedì 20 agosto 2009 11.26
> *To:* 'users at lists.ironpython.com'
> *Subject:* Performances and Profiling of ReportLab under IronPython
>
>
>
> Dear All,
>
>
>
> I downloaded IPY2.6beta2 to test this script:
>
>
>
> from reportlab.graphics.shapes import Drawing, String
>
> from reportlab.graphics import renderPDF
>
>
>
> d = Drawing(100, 100)
>
> s = String(50, 50, "Hello World", textAlign='middle')
>
>
>
> d.add(s)
>
>
>
> renderPDF.drawToFile(d, "HelloWorld.pdf", "HW")
>
>
>
> IPY 2.0.2 takes 20 seconds; IPY 2.6beta2 about 8! But it takes
> long....CPython takes less that a second.
>
>
>
> I have executed profiling from Curt post<http://blogs.msdn.com/curth/archive/2009/03/29/an-ironpython-profiler.aspx>.
> This is the result (first 15 rows, sorted by calls DESC):
>
>
>
> Name
>
> Inclusive
>
> Exclusive
>
> Calls
>
> type Builtin: method: chr(Int32)
>
> 46543
>
> 46543
>
> 1453
>
> type Builtin: method: ord(Object)
>
> 17910
>
> 17910
>
> 888
>
> type List: method: append(Object)
>
> 11752
>
> 11752
>
> 468
>
> type Builtin: method: __import__(CodeContext, String, Object, Object,
> Object, Int32)
>
> 209641377
>
> 209641377
>
> 380
>
> type Builtin: method: hasattr(CodeContext, Object, String)
>
> 771507
>
> 771507
>
> 317
>
> type Builtin: method: divmod(CodeContext, Object, Object)
>
> 99164
>
> 99164
>
> 262
>
> type PythonDictionary: method: has_key(Object)
>
> 48355
>
> 48355
>
> 218
>
> type Builtin: method: len(Object)
>
> 42922
>
> 42922
>
> 189
>
> type StringOps: method: join(String, List)
>
> 19591
>
> 19591
>
> 182
>
> module colors: class Color: def __init__(self, red, green, blue)
>
> 17359
>
> 8780
>
> 150
>
> module colors: def HexColor(val, htmlOnly)
>
> 145565
>
> 6839
>
> 150
>
> type Builtin: method: isinstance(CodeContext, Object, Object)
>
> 6342
>
> 6342
>
> 146
>
> module pdfdoc: def format(element, document, toplevel, InstanceType)
>
> 5712898
>
> 6437
>
> 114
>
> module pdfutils: def _escape(s): def <lambda$840>(c, d)
>
> 4710
>
> 2922
>
> 108
>
> type StringOps: method: lower(String)
>
> 3266
>
> 3266
>
> 100
>
>
>
> Sorted by Inclusive:
>
>
>
> Name
>
> Inclusive
>
> Exclusive
>
> Calls
>
> type Builtin: method: __import__(CodeContext, String, Object, Object,
> Object, Int32)
>
> 209641377
>
> 209641377
>
> 380
>
> module renderPDF01
>
> 61950185
>
> 256
>
> 1
>
> module shapes
>
> 45433217
>
> 1455217
>
> 1
>
> module __init__
>
> 40333697
>
> 53011
>
> 8
>
> module site
>
> 18405008
>
> 1141596
>
> 1
>
> module renderPDF: def drawToFile(d, fn, msg, showBoundary, autoSize)
>
> 13208473
>
> 210
>
> 1
>
> module flowables
>
> 13108755
>
> 64681
>
> 1
>
> module os
>
> 10374697
>
> 101300
>
> 1
>
> module paragraph
>
> 9988916
>
> 104182
>
> 1
>
> module colors
>
> 9227303
>
> 9866
>
> 1
>
> module utils
>
> 7020300
>
> 220690
>
> 1
>
> module canvas: class Canvas: def save(self)
>
> 6521990
>
> 49
>
> 1
>
> module pdfdoc: class PDFDocument: def SaveToFile(self, filename, canvas)
>
> 6493142
>
> 169
>
> 1
>
> module pdfdoc: class PDFDocument: def GetPDFData(self, canvas)
>
> 6215312
>
> 142
>
> 1
>
> module pdfdoc: def format(element, document, toplevel, InstanceType)
>
> 5712898
>
> 6437
>
> 114
>
>
>
> I have not experience: any idea on improving performances? Thanks
>
>
>
> Marco [dot] Parenzan [at] libero [dot] it
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090820/fd6fc36d/attachment.html>
More information about the Ironpython-users
mailing list