2021-02-21 04:53:09 +00:00
|
|
|
#!/usr/bin/env python3
|
2013-01-25 00:46:29 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2021-02-21 04:53:09 +00:00
|
|
|
# Requires Python 2.7 or later
|
2013-01-25 00:46:29 +00:00
|
|
|
|
|
|
|
from __future__ import with_statement
|
2013-08-28 00:44:27 +00:00
|
|
|
from __future__ import unicode_literals
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
import os, string, sys, time, unittest
|
2013-01-25 00:46:29 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
try:
|
|
|
|
start = time.perf_counter()
|
|
|
|
timer = time.perf_counter
|
|
|
|
except AttributeError:
|
|
|
|
timer = time.time
|
|
|
|
|
2022-01-04 23:07:50 +00:00
|
|
|
import XiteWin as Xite
|
2013-01-25 00:46:29 +00:00
|
|
|
|
|
|
|
class TestPerformance(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2013-08-28 00:44:27 +00:00
|
|
|
self.xite = Xite.xiteFrame
|
2013-01-25 00:46:29 +00:00
|
|
|
self.ed = self.xite.ed
|
|
|
|
self.ed.ClearAll()
|
|
|
|
self.ed.EmptyUndoBuffer()
|
|
|
|
|
|
|
|
def testAddLine(self):
|
|
|
|
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2022-12-10 12:35:16 +00:00
|
|
|
for i in range(2000):
|
2013-01-25 00:46:29 +00:00
|
|
|
self.ed.AddText(len(data), data)
|
|
|
|
self.assertEquals(self.ed.LineCount, i + 2)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testAddLine" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
self.assert_(self.ed.Length > 0)
|
|
|
|
|
|
|
|
def testAddLineMiddle(self):
|
|
|
|
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2022-12-10 12:35:16 +00:00
|
|
|
for i in range(2000):
|
2013-01-25 00:46:29 +00:00
|
|
|
self.ed.AddText(len(data), data)
|
|
|
|
self.assertEquals(self.ed.LineCount, i + 2)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testAddLineMiddle" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
self.assert_(self.ed.Length > 0)
|
|
|
|
|
|
|
|
def testHuge(self):
|
|
|
|
data = (string.ascii_letters + string.digits + "\n").encode('utf-8')
|
|
|
|
data = data * 100000
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
self.ed.AddText(len(data), data)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testHuge" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
self.assert_(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)
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2022-12-10 12:35:16 +00:00
|
|
|
for i in range(2000):
|
2013-01-25 00:46:29 +00:00
|
|
|
self.ed.InsertText(0, insert)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testHugeInserts" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
self.assert_(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)
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
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)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-01-25 00:46:29 +00:00
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testHugeReplace" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
self.assert_(self.ed.Length > 0)
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
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')
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2022-12-10 12:35:16 +00:00
|
|
|
for i in range(1000):
|
2013-08-28 00:44:27 +00:00
|
|
|
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.assert_(pos > 0)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-08-28 00:44:27 +00:00
|
|
|
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')
|
2019-05-04 18:14:48 +00:00
|
|
|
start = timer()
|
2022-12-10 12:35:16 +00:00
|
|
|
for i in range(20):
|
2013-08-28 00:44:27 +00:00
|
|
|
self.ed.TargetStart = 0
|
|
|
|
self.ed.TargetEnd = self.ed.Length-1
|
|
|
|
self.ed.SearchFlags = 0
|
|
|
|
pos = self.ed.SearchInTarget(len(searchString), searchString)
|
|
|
|
self.assert_(pos > 0)
|
2019-05-04 18:14:48 +00:00
|
|
|
end = timer()
|
2013-08-28 00:44:27 +00:00
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testUTF8Searches" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
|
2022-12-10 12:35:16 +00:00
|
|
|
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.assert_(pos > 0)
|
|
|
|
end = timer()
|
|
|
|
duration = end - start
|
|
|
|
print("%6.3f testUTF8AsciiSearches" % duration)
|
|
|
|
self.xite.DoEvents()
|
|
|
|
|
2013-01-25 00:46:29 +00:00
|
|
|
if __name__ == '__main__':
|
2013-08-28 00:44:27 +00:00
|
|
|
Xite.main("performanceTests")
|