2 # -*- coding: utf-8 -*-
4 # codimension - graphics python two-way code editor and analyzer
5 # Copyright (C) 2010 Sergey Satskiy <sergey.satskiy@gmail.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 " Speed test for the codimension brief parser "
25 import os
, os
.path
, sys
33 # Shows found errors in the parsed files
37 def collectFiles( path
, files
):
38 " Collects python files "
39 if not path
.endswith( os
.path
.sep
):
41 for item
in os
.listdir( path
):
42 if os
.path
.isdir( path
+ item
):
43 collectFiles( path
+ item
, files
)
44 if os
.path
.isfile( path
+ item
) and \
45 (item
.endswith( ".py" ) or item
.endswith( ".py3" )):
46 if item
.startswith( "__" ):
48 files
.append( os
.path
.abspath( path
+ item
) )
53 def pyclbrTest( files
):
54 " Loop for the library standard parser "
60 tempObj
= pyclbr
.readmodule_ex(
61 os
.path
.basename( item
).replace( ".py", "" ),
62 [os
.path
.dirname( item
)] )
64 print "Error parsing " + item
67 print "pyclbr: processed " + str(count
) + " files"
70 def cdmpyparserTest( files
):
71 " Loop for the codimension parser "
75 # print "Processing " + item + " ..."
76 tempObj
= cdmbriefparser
.getBriefModuleInfoFromFile( item
)
80 print "Failed to parse: " + item
81 for item
in tempObj
.errors
:
83 for item
in tempObj
.lexerErrors
:
86 print "cdmpyparser: processed " + str(count
) + " file(s)"
87 print "cdmpyparser: number of errors: " + str(errorCount
)
91 def deltaToFloat( delta
):
92 " Converts time delta to float "
93 return delta
.seconds
+ delta
.microseconds
/ 1E6
+ delta
.days
* 86400
96 print "Speed test compares the time required for " \
97 "cdmpyparser and the standard pyclbr modules to collect module info."
98 print "cdmpyparser version: " + cdmbriefparser
.getVersion()
103 if len( sys
.argv
) > 1:
104 # File names are expected
105 for fname
in sys
.argv
[ 1: ]:
106 if not os
.path
.exists( fname
):
107 print "Cannot find file specified: '" + fname
+ "'"
109 pythonFiles
.append( os
.path
.abspath( fname
) )
110 print "Files to test: " + str(len(pythonFiles
))
112 print "Collecting a list of python files..."
113 paths
= list( sys
.path
)
117 if os
.path
.isdir( path
):
118 collectFiles( path
, pythonFiles
)
119 pythonFiles
= set( pythonFiles
)
120 print "Collected " + str(len(pythonFiles
))
124 start
= datetime
.datetime
.now()
125 pyclbrTest( pythonFiles
)
126 end
= datetime
.datetime
.now()
130 print "pyclbr timing:"
131 print "Start: " + str( start
)
132 print "End: " + str( end
)
133 print "Delta: " + str( delta
) + " as float: " + str( deltaToFloat( delta
) )
134 print "GC collected: " + str( count
) + " object(s)"
139 # timing for cdmpyparser
140 start
= datetime
.datetime
.now()
141 cdmpyparserTest( pythonFiles
)
142 end
= datetime
.datetime
.now()
146 print "cdmpyparser timing:"
147 print "Start: " + str( start
)
148 print "End: " + str( end
)
149 print "Delta: " + str( delta2
) + " as float: " + str( deltaToFloat( delta2
) )
150 print "GC collected: " + str( count
) + " object(s)"
152 print "\nRatio: " + str( deltaToFloat( delta
) / deltaToFloat( delta2
) )