tags:

views:

61

answers:

1

I wrote a small script for work and when developing it everything was fine but when I turned it over for production use people complained about the time it took to display the first form. Looking into it, all the time seemed to be spent in importing various modules used by the script. I made a new script of just the import statements and a print Hello World and then ran it both as a python script and an executable with the results below. What's going on and is there any way to speed this up?

Python file:

$ for i in {1..10}
> do
>   time ./ipy.exe time.py
> done
real    0m1.712s
real    0m1.701s
real    0m1.689s
real    0m1.691s
real    0m1.709s
real    0m1.663s
real    0m1.697s
real    0m1.700s
real    0m1.699s
real    0m1.741s

exe built with ipy pyc.py /main:time.py /target:exe

$ for i in {1..10}
> do
>   time ./time.exe | grep -v user | grep -v sys
> done
real    0m22.119s
real    0m22.116s
real    0m22.133s
real    0m21.816s
real    0m21.985s
real    0m21.785s
real    0m22.010s
real    0m21.686s
real    0m21.877s
real    0m21.944s

contents of time.py:

import clr
from clr import AddReference
AddReference("System.Windows.Forms")
AddReference("System.Drawing")
AddReference("p4api")
import cgi
from System.Diagnostics import Process
from P4API import *
import System
from System import *
from System.Windows.Forms import *
from System.ComponentModel import *
from System.Drawing import *
from System.Threading import *
import re
import urllib
import os
import tokenize
from cStringIO import StringIO
from optparse import OptionParser
import os
import urllib
import ntpath
import stat
import genericpath
import warnings
import linecache
import types
import UserDict
import _abcoll
import abc
import textwrap
import string
import urlparse
import collections
import keyword
import nturl2path
import mimetools
import tempfile
import random
import __future__
import rfc822
import tokenize
import token
import codecs
import ConfigParser
import uuid
import sys

print "Hello World"
A: 

A combination of adding /platform:x86 to the pcy.py call and running ngen on the resulting dll and exe reduced the execution time of the exe to 1/2 that of the invoking it as a script. I'd call that successful.

Doug-W