1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Requires Python 2.7 or later
from __future__ import with_statement
from __future__ import unicode_literals
import string, time, unittest
try:
start = time.perf_counter()
timer = time.perf_counter
except AttributeError:
timer = time.time
import XiteWin as Xite
class TestPerformance(unittest.TestCase):
def setUp(self):
self.xite = Xite.xiteFrame
self.ed = self.xite.ed
self.ed.ClearAll()
self.ed.EmptyUndoBuffer()
def testAddLine(self):
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
start = timer()
for i in range(2000):
self.ed.AddText(len(data), data)
self.assertEqual(self.ed.LineCount, i + 2)
end = timer()
duration = end - start
print("%6.3f testAddLine" % duration)
self.xite.DoEvents()
self.assertTrue(self.ed.Length > 0)
def testAddLineMiddle(self):
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
start = timer()
for i in range(2000):
self.ed.AddText(len(data), data)
self.assertEqual(self.ed.LineCount, i + 2)
end = timer()
duration = end - start
print("%6.3f testAddLineMiddle" % duration)
self.xite.DoEvents()
self.assertTrue(self.ed.Length > 0)
def testHuge(self):
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
data = data * 100000
start = timer()
self.ed.AddText(len(data), data)
end = timer()
duration = end - start
print("%6.3f testHuge" % duration)
self.xite.DoEvents()
self.assertTrue(self.ed.Length > 0)
def testHugeInserts(self):
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
data = data * 100000
insert = (string.digits + "\n").encode('utf-8')
self.ed.AddText(len(data), data)
start = timer()
for i in range(2000):
self.ed.InsertText(0, insert)
end = timer()
duration = end - start
print("%6.3f testHugeInserts" % duration)
self.xite.DoEvents()
self.assertTrue(self.ed.Length > 0)
def testHugeReplace(self):
oneLine = (string.ascii_letters + string.digits + "\n").encode('utf-8')
data = oneLine * 100000
insert = (string.digits + "\n").encode('utf-8')
self.ed.AddText(len(data), data)
start = timer()
for i in range(1000):
self.ed.TargetStart = i * len(insert)
self.ed.TargetEnd = self.ed.TargetStart + len(oneLine)
self.ed.ReplaceTarget(len(insert), insert)
end = timer()
duration = end - start
print("%6.3f testHugeReplace" % duration)
self.xite.DoEvents()
self.assertTrue(self.ed.Length > 0)
def testUTF8CaseSearches(self):
self.ed.SetCodePage(65001)
oneLine = "Fold Margin=折りたたみ表示用の余白(&F)\n".encode('utf-8')
manyLines = oneLine * 100000
manyLines = manyLines + "φ\n".encode('utf-8')
self.ed.AddText(len(manyLines), manyLines)
searchString = "φ".encode('utf-8')
start = timer()
for i in range(1000):
self.ed.TargetStart = 0
self.ed.TargetEnd = self.ed.Length-1
self.ed.SearchFlags = self.ed.SCFIND_MATCHCASE
pos = self.ed.SearchInTarget(len(searchString), searchString)
self.assertTrue(pos > 0)
end = timer()
duration = end - start
print("%6.3f testUTF8CaseSearches" % duration)
self.xite.DoEvents()
def testUTF8Searches(self):
self.ed.SetCodePage(65001)
oneLine = "Fold Margin=折りたたみ表示用の余白(&F)\n".encode('utf-8')
manyLines = oneLine * 100000
manyLines = manyLines + "φ\n".encode('utf-8')
self.ed.AddText(len(manyLines), manyLines)
searchString = "φ".encode('utf-8')
start = timer()
for i in range(20):
self.ed.TargetStart = 0
self.ed.TargetEnd = self.ed.Length-1
self.ed.SearchFlags = 0
pos = self.ed.SearchInTarget(len(searchString), searchString)
self.assertTrue(pos > 0)
end = timer()
duration = end - start
print("%6.3f testUTF8Searches" % duration)
self.xite.DoEvents()
def testUTF8AsciiSearches(self):
self.ed.SetCodePage(65001)
oneLine = "Fold Margin=NagasakiOsakaHiroshimaHanedaKyoto(&F)\n".encode('utf-8')
manyLines = oneLine * 100000
manyLines = manyLines + "φ\n".encode('utf-8')
self.ed.AddText(len(manyLines), manyLines)
searchString = "φ".encode('utf-8')
start = timer()
for i in range(20):
self.ed.TargetStart = 0
self.ed.TargetEnd = self.ed.Length-1
self.ed.SearchFlags = 0
pos = self.ed.SearchInTarget(len(searchString), searchString)
self.assertTrue(pos > 0)
end = timer()
duration = end - start
print("%6.3f testUTF8AsciiSearches" % duration)
self.xite.DoEvents()
if __name__ == '__main__':
Xite.main("performanceTests")
|