Skip to content

Commit 050cdd1

Browse files
committed
Merge pull request antlr#946 from parrt/master
pull in antlr4-python2 history for runtime files.
2 parents 8df10b2 + c2dfb7f commit 050cdd1

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
__author__ = 'ericvergnaud'
2+
3+
import unittest
4+
import time
5+
import uuid
6+
7+
class TestAtomicPerformance(unittest.TestCase):
8+
9+
# test to check that on the current platform, a < b < c is faster than b in xrange(a,c)
10+
# x in xrange is intensively used in Interval
11+
def test_in_xrange(self):
12+
xstart = time.time()
13+
# check with 20 various range sizes
14+
for max in xrange(0,1000,50):
15+
r = xrange(0,max)
16+
for i in r:
17+
ok = i in r
18+
xend = time.time()
19+
print str((xend-xstart)*1000000)
20+
ystart = time.time()
21+
# check with 20 various range sizes
22+
for max in xrange(0,1000,50):
23+
r = xrange(0,max)
24+
for i in r:
25+
ok = max > i >= 0
26+
yend = time.time()
27+
print str((yend-ystart)*1000000)
28+
self.assertTrue((yend-ystart)<(xend-xstart))
29+
30+
# test to check that on the current platform, hashing string tuples is faster than hashing strings
31+
def test_tuple_hash(self):
32+
# create an array of random strings
33+
s = []
34+
for i in xrange(0,10000):
35+
s.append(str(uuid.uuid4()))
36+
# hash then using string concat
37+
xstart = time.time()
38+
for i in xrange(0,9999):
39+
a = hash(s[i] + s[i+1])
40+
for i in xrange(0,9998):
41+
a = hash(s[i] + s[i+1] + s[i+2])
42+
for i in xrange(0,9997):
43+
a = hash(s[i] + s[i+1] + s[i+2] + s[i+3])
44+
xend = time.time()
45+
print str((xend-xstart)*1000000)
46+
ystart = time.time()
47+
# hash then using string tuple
48+
for i in xrange(0,9999):
49+
a = hash((s[i],s[i+1]))
50+
for i in xrange(0,9998):
51+
a = hash((s[i],s[i+1],s[i+2]))
52+
for i in xrange(0,9997):
53+
a = hash((s[i],s[i+1],s[i+2],s[i+3]))
54+
yend = time.time()
55+
print str((yend-ystart)*1000000)
56+
self.assertTrue((yend-ystart)<(xend-xstart))
57+
58+
59+
if __name__ == '__main__':
60+
unittest.main()

runtime/Python2/src/test/TestXPath.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
__author__ = 'ericvergnaud'
2+
3+
import unittest
4+
import time
5+
import uuid
6+
7+
class TestXPath(unittest.TestCase):
8+
9+
def testLoadable(self):
10+
from antlr4.xpath import XPath
11+
self.assertTrue(True)
12+
13+
14+
15+
16+
if __name__ == '__main__':
17+
unittest.main()

0 commit comments

Comments
 (0)