Escribí un pequeño script para el trabajo y cuando lo desarrollé todo estaba bien pero cuando lo entregué para uso de producción, la gente se quejaba de la hora en que llevó a mostrar el primer formulario. Al examinarlo, todo el tiempo parecía estar invertido en la importación de varios módulos utilizados por el script. Hice una nueva secuencia de comandos de las declaraciones de importación y una impresión Hello World y luego la ejecuté como una secuencia de comandos python y un ejecutable con los resultados a continuación. ¿Qué está pasando y hay alguna forma de acelerar esto?¿Por qué IronPython es mucho más lento para importar módulos cuando se construye como un exe que como un script?
archivo de Python:
$ 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 construido con el API 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
contenido de 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"
Agregar/plataforma: x86 al script de compilación redujo el tiempo de inicio del ejecutable de 22 segundos a 4 segundos, sin embargo, esto es todavía el 250% del script .py. –