summaryrefslogtreecommitdiffstats
path: root/sc/qa/perf/scperfobj.cxx
blob: 17b7345cb2f56c8c51eb447c85b5f8530d40066a (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <test/calc_unoapi_test.hxx>

#include <rtl/ustring.hxx>
#include <cppunit/extensions/HelperMacros.h>
#include <comphelper/processfactory.hxx>

#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XModel2.hpp>

#include <com/sun/star/util/XSearchable.hpp>
#include <com/sun/star/util/XSearchDescriptor.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/sheet/XSpreadsheets.hpp>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sheet/XArrayFormulaRange.hpp>
#include <com/sun/star/sheet/XCalculatable.hpp>
#include <com/sun/star/table/XCellRange.hpp>
#include <com/sun/star/sheet/XCellRangeFormula.hpp>
#include <com/sun/star/sheet/XNamedRanges.hpp>
#include <com/sun/star/table/XCell.hpp>
#include <com/sun/star/table/CellAddress.hpp>
#include <com/sun/star/table/CellRangeAddress.hpp>
#include <com/sun/star/sheet/Border.hpp>
#include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
#include <com/sun/star/sheet/SubTotalColumn.hpp>
#include <com/sun/star/sheet/GeneralFunction.hpp>

#include <test/callgrind.hxx>

#include <calcconfig.hxx>
#include <docsh.hxx>
#include <tabvwsh.hxx>

using namespace css;
using namespace css::uno;

namespace sc_apitest {

class ScPerfObj : public CalcUnoApiTest
{
public:

    ScPerfObj();

    virtual void tearDown() override;

    uno::Reference< uno::XInterface > init(const OUString& aFileName);

    CPPUNIT_TEST_SUITE(ScPerfObj);
    CPPUNIT_TEST(testSheetFindAll);
    CPPUNIT_TEST(testFixedSum);
    CPPUNIT_TEST(testSheetNamedRanges);
    CPPUNIT_TEST(testSheets);
    CPPUNIT_TEST(testSum);
    CPPUNIT_TEST(testFTest);
    CPPUNIT_TEST(testChiTest);
    CPPUNIT_TEST(testSumX2PY2Test);
    CPPUNIT_TEST(testTTest);
    CPPUNIT_TEST(testLcm);
    CPPUNIT_TEST(testGcd);
    CPPUNIT_TEST(testPearson);
    CPPUNIT_TEST(testSubTotalWithFormulas);
    CPPUNIT_TEST(testSubTotalWithoutFormulas);
    CPPUNIT_TEST(testLoadingFileWithSingleBigSheet);
    CPPUNIT_TEST(testMatConcatSmall);
    CPPUNIT_TEST(testMatConcatLarge);
    CPPUNIT_TEST_SUITE_END();

private:

    uno::Reference< lang::XComponent > mxComponent;

    // tests
    void testSheetFindAll();
    void testSheetNamedRanges();
    void testSheets();
    void testSum();
    void testFTest();
    void testChiTest();
    void testSumX2PY2Test();
    void testTTest();
    void testLcm();
    void testGcd();
    void testPearson();
    void testSubTotalWithFormulas();
    void testSubTotalWithoutFormulas();
    void testLoadingFileWithSingleBigSheet();
    void testFixedSum();
    void testMatConcatSmall();
    void testMatConcatLarge();
};

ScPerfObj::ScPerfObj()
    : CalcUnoApiTest("sc/qa/perf/testdocuments/")
{
}

uno::Reference< uno::XInterface > ScPerfObj::init(const OUString& aFileName)
{
    OUString aFileURL;
    createFileURL(aFileName, aFileURL);

    mxComponent = loadFromDesktop(aFileURL);

    CPPUNIT_ASSERT(mxComponent.is());

    return mxComponent;
}

void ScPerfObj::tearDown()
{
    if (mxComponent.is())
    {
        closeDocument(mxComponent);
        mxComponent.clear();
    }
    CalcUnoApiTest::tearDown();
}

void ScPerfObj::testSheetFindAll()
{

    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scBigFile.ods"), UNO_QUERY_THROW);

    // get sheet
    uno::Reference< container::XIndexAccess > xSheetIndex (xDoc->getSheets(), UNO_QUERY_THROW);

    uno::Reference< sheet::XSpreadsheet > xSheet( xSheetIndex->getByIndex(0), UNO_QUERY_THROW);

    // create descriptor
    uno::Reference< util::XSearchable > xSearchable(xSheet, UNO_QUERY_THROW);
    uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor();

    // search for a value
    xSearchDescr->setSearchString("value_1");

    callgrindStart();

    uno::Reference< container::XIndexAccess > xIndex = xSearchable->findAll(xSearchDescr);

    callgrindDump("sc:search_all_sheets_by_value");

    CPPUNIT_ASSERT(xIndex.is());

    int nCount = xIndex->getCount();

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Count" , 20000, nCount);

    // search for style
    uno::Reference< sheet::XSpreadsheet > xSheet2( xSheetIndex->getByIndex(2), UNO_QUERY_THROW);
    uno::Reference< util::XSearchable > xSearchableStyle(xSheet2, UNO_QUERY_THROW);
    xSearchDescr = xSearchableStyle->createSearchDescriptor();

    uno::Reference< beans::XPropertySet > xSearchProp(xSearchDescr,UNO_QUERY_THROW);
    xSearchProp->setPropertyValue("SearchStyles", makeAny(true));

    xSearchDescr->setSearchString("aCellStyle");

    callgrindStart();

    uno::Reference< container::XIndexAccess > xIndex2 = xSearchableStyle->findAll(xSearchDescr);

    callgrindDump("sc:search_all_sheets_by_style");

    CPPUNIT_ASSERT(xIndex2.is());

    nCount = xIndex2->getCount();

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Count" , 160, nCount);

}

void ScPerfObj::testSheetNamedRanges()
{

    uno::Reference< lang::XComponent > xComponent (init("scBigFile.ods"), UNO_QUERY_THROW);
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);

    // get NamedRanges
    uno::Reference< beans::XPropertySet > xPropSet (xComponent, UNO_QUERY_THROW);
    OUString aNamedRangesPropertyString("NamedRanges");
    uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue(aNamedRangesPropertyString), UNO_QUERY_THROW);
    uno::Reference< container::XIndexAccess > xIndexNamedRanges(xNamedRanges, UNO_QUERY_THROW);

    // get sheet - named ranges are defined in sheet #1
    uno::Reference< container::XIndexAccess > xSheetIndex (xDoc->getSheets(), UNO_QUERY_THROW);
    uno::Reference< sheet::XSpreadsheet > xSheet( xSheetIndex->getByIndex(1), UNO_QUERY_THROW);

    // test removeByName
    OUString maNameToRemove("namedRange_4999");
    bool bHasIt = xNamedRanges->hasByName(maNameToRemove);
    CPPUNIT_ASSERT_MESSAGE("NamedRange initial1 does not exist, can't remove it", bHasIt);

    if (bHasIt)
    {
        callgrindStart();
        xNamedRanges->removeByName(maNameToRemove);
        callgrindDump("sc:remove_named_range_by_name");
    }

    // test addNewByName
    table::CellAddress aBaseAddress = table::CellAddress(0,0,0);

    sal_Int32 nType = 0;
    OUString aContent1("B4999");
    OUString aName1("single_added");
    callgrindStart();
    xNamedRanges->addNewByName(aName1, aContent1, aBaseAddress, nType);
    callgrindDump("sc:add_named_range_by_name");

    //test AddNewFromTitles with some 1000 new named ranges
    table::CellRangeAddress aCellRangeAddress = table::CellRangeAddress(0,1,0,2,999);
    callgrindStart();
    xNamedRanges->addNewFromTitles(aCellRangeAddress, sheet::Border_LEFT);
    callgrindDump("sc:add_named_range_from_titles");

}

void ScPerfObj::testSheets()
{

    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scBigFile.ods"), UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    OUString aSheetName = "NewSheet";

    callgrindStart();
    xSheets->insertNewByName(aSheetName, 80);
    callgrindDump("sc:insert_new_sheet_by_name");

    OUString aSourceSheetName = "aSheet_2";
    OUString aTargetSheetName = "aCopiedSheet";

    callgrindStart();
    xSheets->copyByName(aSourceSheetName, aTargetSheetName, 70);
    callgrindDump("sc:copy_sheet_by_name");

    uno::Reference< sheet::XSpreadsheets > xSheetsNameContainer (xSheets, UNO_SET_THROW);

    callgrindStart();
    xSheetsNameContainer->removeByName(aSheetName);
    callgrindDump("sc:remove_sheet_by_name");

}

void ScPerfObj::testSum()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("SumSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(1, 0);


    callgrindStart();
    xCell->setFormula("=SUM(A1:A10000)");
    xCalculatable->calculate();
    callgrindDump("sc:sum_numbers_column");

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Sum" , 504178.0, xCell->getValue());

    // query for the XCellRange interface
    uno::Reference< table::XCellRange > rCellRange(rSheet, UNO_QUERY);
    // query the cell range
    uno::Reference< table::XCellRange > xCellRange = rCellRange->getCellRangeByName("B1");

    uno::Reference< sheet::XArrayFormulaRange > xArrayFormulaRange(xCellRange, UNO_QUERY_THROW);

    callgrindStart();
    xArrayFormulaRange->setArrayFormula("=SUM(A1:A10000=30)");
    xCalculatable->calculate();
    callgrindDump("sc:sum_with_array_formula_condition");

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Sum - number of elements equal 30" , 99.0, xCell->getValue());
}

void ScPerfObj::testFTest()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("FTestSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(0, 0);

    callgrindStart();
    xCell->setFormula("=FTEST(B1:K10;L1:U10)");
    xCalculatable->calculate();
    callgrindDump("sc:ftest");

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong FTest result" , 0.8909, xCell->getValue(), 10e-4);
}

void ScPerfObj::testChiTest()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("ChiTestSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(0, 0);

    callgrindStart();
    xCell->setFormula("=CHITEST(B1:CV100;CW1:GQ100)");
    xCalculatable->calculate();
    callgrindDump("sc:chitest");

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong ChiTest result" , 0.0, xCell->getValue(), 10e-4);
}

void ScPerfObj::testSumX2PY2Test()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions2.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("SumX2PY2Sheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(2, 0);

    callgrindStart();
    xCell->setFormula("=SUMX2PY2(A1:A10000;B1:B10000)");
    xCalculatable->calculate();
    callgrindDump("sc:sumx2py2");

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong SumX2PY2 result" , 574539.0, xCell->getValue());
}

void ScPerfObj::testTTest()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions2.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("TTestSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(0, 0);

    callgrindStart();
    xCell->setFormula("=T.TEST(B1:CV100;CW1:GQ100;2;1)");
    xCalculatable->calculate();
    callgrindDump("sc:ttest");

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong TTest result" , 0.0, xCell->getValue());
}

void ScPerfObj::testLcm()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions2.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("LCMSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(1, 0);

    callgrindStart();
    xCell->setFormula("=LCM(A1:A10000)");
    xCalculatable->calculate();
    callgrindDump("sc:lcm");

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong LCM" , 2520.0, xCell->getValue());
}

void ScPerfObj::testGcd()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions2.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("GCDSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(1, 0);

    callgrindStart();
    xCell->setFormula("=GCD(A1:A10000)");
    xCalculatable->calculate();
    callgrindDump("sc:gcd");

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong GCD", 3.0, xCell->getValue());
}

void ScPerfObj::testPearson()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions2.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("PearsonSheet");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);
    uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(0, 0);

    callgrindStart();
    xCell->setFormula("=PEARSON(B1:CV100;CW1:GQ100)");
    xCalculatable->calculate();
    callgrindDump("sc:pearson");

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Wrong Pearson result" , 0.01255, xCell->getValue(), 10e-4);
}

void ScPerfObj::testSubTotalWithFormulas()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scBigSingleSheet200.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);
    uno::Any rSheet = xSheets->getByName("scBigSingleSheet");

    // query for the XCellRange interface
    uno::Reference< table::XCellRange > rCellRange(rSheet, UNO_QUERY);

    // query the cell range
    uno::Reference< table::XCellRange > xCellRange = rCellRange->getCellRangeByPosition(0,0,1023,1000000);

    // Create the subtotal interface
    uno::Reference< sheet::XSubTotalCalculatable > xSub(xCellRange, UNO_QUERY_THROW);
    uno::Reference< sheet::XSubTotalDescriptor > xSubDesc = xSub->createSubTotalDescriptor(true);

    // Create the column used for subtotal
    uno::Sequence < sheet::SubTotalColumn > xSubTotalColumns;
    xSubTotalColumns.realloc(1);

    // Add the column to the descriptor
    xSubTotalColumns[0].Column   = 1;
    xSubTotalColumns[0].Function = sheet::GeneralFunction_SUM;

    xSubDesc->addNew(xSubTotalColumns, 0);

    // Run the subtotal function
    callgrindStart();
    xSub->applySubTotals(xSubDesc, true);
    callgrindDump("sc:doSubTotal_on_large_sheet_with_formulas");
}

void ScPerfObj::testSubTotalWithoutFormulas()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scBigSingleSheet200.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);
    uno::Any rSheet = xSheets->getByName("scBigSingleSheet");

    // query for the XCellRange interface
    uno::Reference< table::XCellRange > rCellRange(rSheet, UNO_QUERY);

    // query the cell range
    uno::Reference< table::XCellRange > xCellRange = rCellRange->getCellRangeByPosition(0,0,10,1000000);

    // Create the subtotal interface
    uno::Reference< sheet::XSubTotalCalculatable > xSub(xCellRange, UNO_QUERY_THROW);
    uno::Reference< sheet::XSubTotalDescriptor > xSubDesc = xSub->createSubTotalDescriptor(true);

    // Create the column used for subtotal
    uno::Sequence < sheet::SubTotalColumn> xSubTotalColumns;
    xSubTotalColumns.realloc(1);

    // Add the column to the descriptor
    xSubTotalColumns[0].Column   = 1;
    xSubTotalColumns[0].Function = sheet::GeneralFunction_SUM;

    xSubDesc->addNew(xSubTotalColumns, 0);

    // Run the subtotal function
    callgrindStart();
    xSub->applySubTotals(xSubDesc, true);
    callgrindDump("sc:doSubTotal_on_large_sheet_without_formulas");
}

void ScPerfObj::testLoadingFileWithSingleBigSheet()
{
    callgrindStart();
    uno::Reference< sheet::XSpreadsheetDocument > xDoc1(init("scBigSingleSheet2000.ods"), UNO_QUERY_THROW);
    uno::Reference< sheet::XCalculatable > xCalculatable1(xDoc1, UNO_QUERY_THROW);
    callgrindDump("sc:loadingFileWithSingleBigSheetdoSubTotal_2000lines");
}

namespace {
    void setupBlockFormula(
        const uno::Reference< sheet::XSpreadsheetDocument > & xDoc,
        const OUString &rSheetName,
        const OUString &rCellRange,
        const OUString &rFormula)
    {
        uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

        uno::Any aSheet = xSheets->getByName(rSheetName);
        uno::Reference< table::XCellRange > xSheetCellRange(aSheet, UNO_QUERY);
        uno::Reference< sheet::XCellRangeFormula > xCellRange(
            xSheetCellRange->getCellRangeByName(rCellRange), UNO_QUERY);

        uno::Sequence< uno::Sequence< OUString > > aFormulae(1000);
        for (sal_Int32 i = 0; i < 1000; ++i)
        {
            uno::Sequence< OUString > aRow(1);
            aRow[0] = rFormula;
            aFormulae[i] = aRow;
        }

        // NB. not set Array (matrix) formula
        xCellRange->setFormulaArray(aFormulae);
    }
}

void ScPerfObj::testFixedSum()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("scMathFunctions3.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    setupBlockFormula(xDoc, "FixedSumSheet", "B1:B1000", "=SUM(A$1:A$1000)");

    callgrindStart();
    xCalculatable->calculateAll();
    callgrindDump("sc:sum_with_fixed_array_formula");

    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);
    uno::Any aSheet = xSheets->getByName("FixedSumSheet");
    uno::Reference< sheet::XSpreadsheet > xSheet (aSheet, UNO_QUERY);

    for( sal_Int32 i = 0; i < 1000; ++i )
    {
        uno::Reference< table::XCell > xCell = xSheet->getCellByPosition(1, i);
        CPPUNIT_ASSERT_DOUBLES_EQUAL(50206.0, xCell->getValue(), 1e-12);
    }
}

void ScPerfObj::testMatConcatSmall()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("empty.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("Sheet1");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);

    // query for the XCellRange interface
    uno::Reference< table::XCellRange > rCellRange(rSheet, UNO_QUERY);
    // query the cell range
    uno::Reference< table::XCellRange > xCellRange = rCellRange->getCellRangeByName("C1");

    uno::Reference< sheet::XArrayFormulaRange > xArrayFormulaRange(xCellRange, UNO_QUERY_THROW);

    xArrayFormulaRange->setArrayFormula("=A1:A20&B1:B20");
    callgrindStart();
    xCalculatable->calculateAll();
    callgrindDump("sc:mat_concat_small");
}

void ScPerfObj::testMatConcatLarge()
{
    uno::Reference< sheet::XSpreadsheetDocument > xDoc(init("empty.ods"), UNO_QUERY_THROW);

    uno::Reference< sheet::XCalculatable > xCalculatable(xDoc, UNO_QUERY_THROW);

    // get getSheets
    uno::Reference< sheet::XSpreadsheets > xSheets (xDoc->getSheets(), UNO_SET_THROW);

    uno::Any rSheet = xSheets->getByName("Sheet1");

    // query for the XSpreadsheet interface
    uno::Reference< sheet::XSpreadsheet > xSheet (rSheet, UNO_QUERY);

    // query for the XCellRange interface
    uno::Reference< table::XCellRange > rCellRange(rSheet, UNO_QUERY);
    // query the cell range
    uno::Reference< table::XCellRange > xCellRange = rCellRange->getCellRangeByName("C1");

    uno::Reference< sheet::XArrayFormulaRange > xArrayFormulaRange(xCellRange, UNO_QUERY_THROW);

    callgrindStart();
    xArrayFormulaRange->setArrayFormula("=A1:A30000&B1:B30000");
    xCalculatable->calculate();
    callgrindDump("sc:mat_concat");
}

CPPUNIT_TEST_SUITE_REGISTRATION(ScPerfObj);

}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */