diff options
author | Neil <nyamatongwe@gmail.com> | 2018-04-18 08:48:37 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-04-18 08:48:37 +1000 |
commit | e16b365fa138a7c2f0eaa1406cfeca406235a0c5 (patch) | |
tree | bb1b8881deadecd47429771a33e594920a329c70 /test/performanceTests.py | |
parent | 652f4c0471ee7b98b1012128eadd66b21fc06dd6 (diff) | |
download | scintilla-mirror-e16b365fa138a7c2f0eaa1406cfeca406235a0c5.tar.gz |
Check for perf_counter before using as not available on Python 2 used for PySide
on Linux.
Diffstat (limited to 'test/performanceTests.py')
-rw-r--r-- | test/performanceTests.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/test/performanceTests.py b/test/performanceTests.py index 754155ee3..bfbae5fe9 100644 --- a/test/performanceTests.py +++ b/test/performanceTests.py @@ -5,6 +5,12 @@ from __future__ import unicode_literals import os, string, sys, time, unittest +try: + start = time.perf_counter() + timer = time.perf_counter +except AttributeError: + timer = time.time + if sys.platform == "win32": import XiteWin as Xite else: @@ -20,11 +26,11 @@ class TestPerformance(unittest.TestCase): def testAddLine(self): data = (string.ascii_letters + string.digits + "\n").encode('utf-8') - start = time.perf_counter() + start = timer() for i in range(1000): self.ed.AddText(len(data), data) self.assertEquals(self.ed.LineCount, i + 2) - end = time.perf_counter() + end = timer() duration = end - start print("%6.3f testAddLine" % duration) self.xite.DoEvents() @@ -32,11 +38,11 @@ class TestPerformance(unittest.TestCase): def testAddLineMiddle(self): data = (string.ascii_letters + string.digits + "\n").encode('utf-8') - start = time.perf_counter() + start = timer() for i in range(1000): self.ed.AddText(len(data), data) self.assertEquals(self.ed.LineCount, i + 2) - end = time.perf_counter() + end = timer() duration = end - start print("%6.3f testAddLineMiddle" % duration) self.xite.DoEvents() @@ -45,9 +51,9 @@ class TestPerformance(unittest.TestCase): def testHuge(self): data = (string.ascii_letters + string.digits + "\n").encode('utf-8') data = data * 100000 - start = time.perf_counter() + start = timer() self.ed.AddText(len(data), data) - end = time.perf_counter() + end = timer() duration = end - start print("%6.3f testHuge" % duration) self.xite.DoEvents() @@ -58,10 +64,10 @@ class TestPerformance(unittest.TestCase): data = data * 100000 insert = (string.digits + "\n").encode('utf-8') self.ed.AddText(len(data), data) - start = time.perf_counter() + start = timer() for i in range(1000): self.ed.InsertText(0, insert) - end = time.perf_counter() + end = timer() duration = end - start print("%6.3f testHugeInserts" % duration) self.xite.DoEvents() @@ -72,12 +78,12 @@ class TestPerformance(unittest.TestCase): data = oneLine * 100000 insert = (string.digits + "\n").encode('utf-8') self.ed.AddText(len(data), data) - start = time.perf_counter() + 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 = time.perf_counter() + end = timer() duration = end - start print("%6.3f testHugeReplace" % duration) self.xite.DoEvents() @@ -90,14 +96,14 @@ class TestPerformance(unittest.TestCase): manyLines = manyLines + "φ\n".encode('utf-8') self.ed.AddText(len(manyLines), manyLines) searchString = "φ".encode('utf-8') - start = time.perf_counter() + start = timer() for i in range(10): 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) - end = time.perf_counter() + end = timer() duration = end - start print("%6.3f testUTF8CaseSearches" % duration) self.xite.DoEvents() @@ -109,14 +115,14 @@ class TestPerformance(unittest.TestCase): manyLines = manyLines + "φ\n".encode('utf-8') self.ed.AddText(len(manyLines), manyLines) searchString = "φ".encode('utf-8') - start = time.perf_counter() + start = timer() for i in range(10): 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 = time.perf_counter() + end = timer() duration = end - start print("%6.3f testUTF8Searches" % duration) self.xite.DoEvents() |