Bug 154215 - The WeekNum worksheet function is very slow
Summary: The WeekNum worksheet function is very slow
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: perf
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2023-03-15 20:59 UTC by NOYB
Modified: 2023-03-19 11:56 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description NOYB 2023-03-15 20:59:17 UTC
Description:
More than 1000x > than Excel


Steps to Reproduce:
1. Run the code in the other information section.
2.
3.

Actual Results:
12 seconds for 10K WeekNum() calls (> 1ms per)
More than 1000x > than Excel


Expected Results:
Reasonably close to Excel performance (< 10x)
0.101 seconds for 10K WeekNum() calls



Reproducible: Always


User Profile Reset: No

Additional Info:
Option VBASupport 1
Sub WeekNum_Function_Performance()
    Dim T1 As Single
    Dim T2 As Single

    With WorksheetFunction
    
    T1 = Timer()
    For i = 1 To 10000
        WkNum = .WeekNum("03/14/2023", 1)
    Next i
    T2 = Timer()

    End With

    MsgBox ("Iterations: " & i & ", Time: " & T2 - T1)
End Sub
Comment 1 Eike Rathke 2023-03-15 22:23:48 UTC
VBASupport is a compatibility layer, so don't expect speed. Any invocation of WorksheetFunction.something() requires overhead that can't be neglected. You'd probably save some time using the com.sun.star.sheet.FunctionAccess service directly from BASIC.
See https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1sheet_1_1FunctionAccess.html
Comment 2 NOYB 2023-03-15 22:41:02 UTC
I realize VBA is a compatibility layer and do expect a performance hit.  But a 1000 x performance hit?  Seriously?

Actually it even more the 1000 x because the system used for the Excel benchmark is 10 years old and much slower machine.  1.8GHz compared to 2.4GHz.

The performance difference is probably near 2000 x.

That doesn't seem reasonable even for compatibility.  Even though it technically functions.  With the much of a performance hit, it's essentially not compatible.

Pretty sure there is plenty of room for improvement.