Skip to content

Commit b3813c8

Browse files
committed
Adapt the speed tests for PyPy.
1 parent 7a72df6 commit b3813c8

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

‎tinycss/tests/speed.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,45 @@ def parse_cssutils():
8181

8282

8383
defcheck_consistency():
84+
result=parse_python()
8485
#import pprint
85-
#pprint.pprint(parse_python())
86-
result=parse_cython()
86+
#pprint.pprint(result)
8787
assertlen(result) >0
88-
assertparse_python() ==result
88+
iftokenizer.cython_tokenize_flat:
89+
assertparse_cython() ==result
8990
assertparse_cssutils() ==result
9091
version='.'.join(map(str, sys.version_info[:3]))
9192
print('Python{}, consistency OK.'.format(version))
9293

9394

95+
defwarm_up():
96+
is_pypy=hasattr(sys, 'pypy_translation_info')
97+
ifis_pypy:
98+
print('Warming up for PyPy...')
99+
foriinrange(80):
100+
foriinrange(10):
101+
parse_python()
102+
parse_cssutils()
103+
sys.stdout.write('.')
104+
sys.stdout.flush()
105+
sys.stdout.write('\n')
106+
107+
94108
deftime(function):
95109
seconds=timeit.Timer(function).repeat(TIMEIT_REPEAT, TIMEIT_NUMBER)
96110
miliseconds=int(min(seconds) *1000)
97111
returnmiliseconds
98112

99113

100114
defrun():
101-
data_set= [
102-
('tinycss + speedups ', parse_cython),
115+
iftokenizer.cython_tokenize_flat:
116+
data_set= [
117+
('tinycss + speedups ', parse_cython),
118+
]
119+
else:
120+
print('Speedups are NOT available.')
121+
data_set= []
122+
data_set+= [
103123
('tinycss WITHOUT speedups', parse_python),
104124
('cssutils ', parse_cssutils),
105125
]
@@ -113,4 +133,5 @@ def run():
113133

114134
if__name__=='__main__':
115135
check_consistency()
136+
warm_up()
116137
run()

0 commit comments

Comments
(0)