PiotrDabkowski / pyjsparser

Fast JavaScript parser for Python.
MIT License
246 stars 37 forks source link

why import is very slowly? #22

Closed walkinrain2008 closed 5 years ago

walkinrain2008 commented 5 years ago

i use pyjsparser in my program

import pyjsparser or from pyjsparser import PyJsParser

when program run , it takes as long time to import . about 2 seconds for import 。 env: os: win10 1609 cpu: AMD athlon II x3 450 mem: 6G py : python 3.7 win32

PiotrDabkowski commented 5 years ago

For me the import is faster than that (0.5s), it takes some time because of constants being defined in pyjsparser/pyjsparser/pyjsparserdata.py. This could be in theory delayed until the parser is actually used.

walkinrain2008 commented 5 years ago

i test code , import pyjsparserdata.py is slowly in line 224

    for c in map(unichr, range(sys.maxunicode + 1)):
        U_CATEGORIES[unicodedata.category(c)].append(c)

test code :

print("begin")
ticks = []
import time
tick_s = time.perf_counter()
import pyjsparser.pyjsparserdata
ticks.append(time.perf_counter() - tick_s)
print("import time =",ticks)

result: begin import time = [1.543109415]