Added performance testing for atomic operations

This commit is contained in:
ericvergnaud 2015-01-17 23:52:38 +08:00
parent 087b7902eb
commit 75486e0a51
4 changed files with 103 additions and 3 deletions

View File

@ -1,3 +1,4 @@
This is the Python 3.4 runtime for AntLR.
Visit the AntLR web site for more information:
http://www.antlr.org
Visit the AntLR web sites for more information:
http://www.antlr.org
http://theantlrguy.atlassian.net/wiki/display/ANTLR4/Python+Target

12
RELEASE-4.5.txt Normal file
View File

@ -0,0 +1,12 @@
What's in this release?
- fixed bug where non-ascii input streams would fail
- added support for visitor pattern
- added support for wildcards in grammar
Breaking change:
In version 4.4, the parser/lexer had a tokenNames member.
This has been removed in favor of the following members:
- lexicalNames, containing the parsed text
- symbolicNames, corresponding to tokenNames

View File

@ -8,6 +8,6 @@ setup(
url='http://www.antlr.org',
license='BSD',
author='Eric Vergnaud, Terence Parr, Sam Harwell',
author_email='eric@test',
author_email='eric.vergnaud@wanadoo.fr',
description='ANTLR 4.5 runtime for Python 3.4.0'
)

View File

@ -0,0 +1,87 @@
__author__ = 'ericvergnaud'
import unittest
import time
import uuid
import io
class TestAtomicPerformance(unittest.TestCase):
# test to check that on the current platform, a < b < c is faster than b in range(a,c)
# x in xrange is intensively used in Interval
def test_in_range(self):
xstart = time.time()
# check with 20 various range sizes
for max in range(0,1000,50):
r = range(0,max)
for i in r:
ok = i in r
xend = time.time()
print(str((xend-xstart)*1000000))
ystart = time.time()
# check with 20 various range sizes
for max in range(0,1000,50):
r = range(0,max)
for i in r:
ok = max > i >= 0
yend = time.time()
print(str((yend-ystart)*1000000))
self.assertTrue((yend-ystart)<(xend-xstart))
# test to check that on the current platform, hashing string tuples is faster than hashing strings
def test_tuple_hash(self):
# create an array of random strings
s = []
for i in range(0,10000):
s.append(str(uuid.uuid4()))
# hash then using string concat
xstart = time.time()
for i in range(0,9999):
a = hash(s[i] + s[i+1])
for i in range(0,9998):
a = hash(s[i] + s[i+1] + s[i+2])
for i in range(0,9997):
a = hash(s[i] + s[i+1] + s[i+2] + s[i+3])
xend = time.time()
print(str((xend-xstart)*1000000))
ystart = time.time()
# hash then using string tuple
for i in range(0,9999):
a = hash((s[i],s[i+1]))
for i in range(0,9998):
a = hash((s[i],s[i+1],s[i+2]))
for i in range(0,9997):
a = hash((s[i],s[i+1],s[i+2],s[i+3]))
yend = time.time()
print(str((yend-ystart)*1000000))
self.assertTrue((yend-ystart)<(xend-xstart))
zstart = time.time()
# hash then using string tuple
for i in range(0,9999):
b = io.StringIO()
b.write(s[i])
b.write(s[i+1])
a = hash(b.getvalue())
b.close()
for i in range(0,9998):
b = io.StringIO()
b.write(s[i])
b.write(s[i+1])
b.write(s[i+2])
a = hash(b.getvalue())
b.close()
for i in range(0,9997):
b = io.StringIO()
b.write(s[i])
b.write(s[i+1])
b.write(s[i+2])
b.write(s[i+3])
a = hash(b.getvalue())
b.close()
zend = time.time()
print(str((zend-zstart)*1000000))
self.assertTrue((yend-ystart)<(zend-zstart))
if __name__ == '__main__':
unittest.main()