diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-05-10 15:45:25 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-05-20 20:13:04 -0400 |
commit | 7476ad63d168dd43785df86485819fd299522fc5 (patch) | |
tree | 2bcd5a23e0fcb03db04b7982fc84fb18c6eb36f7 /sc/qa | |
parent | 0fb3bfcae4da8e6e056a05ec0ec351cc908c7192 (diff) |
First (?) performance regression unit test against clearing of a sheet.
I screwed this up earlier which made this operation take almost 50 seconds
to complete. It should finish in 0.00001 seconds or less. The test checks
against 1 second, which should be enough of a buffer for slower machines.
Change-Id: I9923033045111c75a0740b6bb30a518fe93e01d2
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 940b41edb0aa..3e881c9b7ba5 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -11,6 +11,7 @@ #include <rtl/strbuf.hxx> #include <osl/file.hxx> +#include <osl/time.h> #include "scdll.hxx" #include "formulacell.hxx" @@ -91,6 +92,16 @@ using ::std::vector; namespace { +double getTimeDiff(const TimeValue& t1, const TimeValue& t2) +{ + double tv1 = t1.Seconds; + double tv2 = t2.Seconds; + tv1 += t1.Nanosec / 1000000000.0; + tv2 += t2.Nanosec / 1000000000.0; + + return tv1 - tv2; +} + class Test : public test::BootstrapFixture { public: Test(); @@ -98,6 +109,12 @@ public: virtual void setUp(); virtual void tearDown(); + /** + * Basic performance regression test. Pick some actions that *should* take + * only a fraction of a second to complete, and make sure they stay that + * way. + */ + void testPerf(); void testCollator(); void testRangeList(); void testInput(); @@ -265,6 +282,7 @@ public: void testCondFormatINSDEL(); CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testPerf); CPPUNIT_TEST(testCollator); CPPUNIT_TEST(testRangeList); CPPUNIT_TEST(testInput); @@ -448,6 +466,29 @@ void Test::tearDown() BootstrapFixture::tearDown(); } +void Test::testPerf() +{ + CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet", m_pDoc->InsertTab (0, "foo")); + + TimeValue aTimeBefore, aTimeAfter; + + // Clearing an already empty sheet should finish in a fraction of a + // second. Flag failure if it takes more than one second. Clearing 100 + // columns should be large enough to flag if something goes wrong. + osl_getSystemTime(&aTimeBefore); + clearRange(m_pDoc, ScRange(0,0,0,99,MAXROW,0)); + osl_getSystemTime(&aTimeAfter); + double diff = getTimeDiff(aTimeAfter, aTimeBefore); + if (diff >= 1.0) + { + std::ostringstream os; + os << "Clearing an empty sheet took " << diff << " seconds. It should be instant."; + CPPUNIT_FAIL(os.str().c_str()); + } + + m_pDoc->DeleteTab(0); +} + void Test::testCollator() { OUString s1("A"); @@ -1732,6 +1773,17 @@ void Test::testCellBroadcaster() CPPUNIT_ASSERT_MESSAGE("Deleted reference check in B3 failed.", checkDeletedRefToken(*m_pDoc, ScAddress(1,2,0))); + // Clear everything again + clearRange(m_pDoc, ScRange(0,0,0,10,100,0)); + + m_pDoc->SetString(ScAddress(1,0,0), "=A1"); // B1 references A1. + m_pDoc->SetValue(ScAddress(0,0,0), 12.3); + CPPUNIT_ASSERT_EQUAL(12.3, m_pDoc->GetValue(ScAddress(1,0,0))); + + // Clear the entire column A. + clearRange(m_pDoc, ScRange(0,0,0,0,MAXROW,0)); + CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(ScAddress(1,0,0))); + m_pDoc->DeleteTab(0); } |