Skip to content

Commit

Permalink
Merge pull request #82 from fslaborg/speed
Browse files Browse the repository at this point in the history
improve rowWithRange SkipSearch performance
  • Loading branch information
HLWeil committed Jan 30, 2024
2 parents 8b8c080 + 66b6713 commit fc5f16f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 5.1.1+e7cc638 (Released 2024-1-26)
* Additions:
* [[#e7cc638](https://github.com/CSBiology/FsSpreadsheet/commit/e7cc638b170c570005b6cd8378d1e0ac31075be7)] improve rowWithRange SkipSearch performance

### 5.1.0+4732d22 (Released 2024-1-24)
* Additions:
* Increase Parser speed
Expand Down
2 changes: 1 addition & 1 deletion build/ReleaseTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let publishNPM = BuildTask.create "PublishNPM" [clean; build; runTests; packJS]
let msg = sprintf "[NPM] release package with version %s?" stableVersionTag
if promptYesNo msg then
let apikey = Environment.environVarOrNone "NPM_KEY"
let otp = if apikey.IsSome then $" --otp + {apikey.Value}" else ""
let otp = if apikey.IsSome then $" --otp {apikey.Value}" else ""
run npm $"publish --access public{otp}" ProjectInfo.npmPkgDir
else failwith "aborted"
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fslab/fsspreadsheet",
"version": "5.1.0",
"version": "5.1.1",
"description": "Minimal spreadsheet creation and manipulation using exceljs io.",
"type": "module",
"main": "Xlsx.js",
Expand Down
10 changes: 8 additions & 2 deletions src/FsSpreadsheet/FsWorksheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ type FsWorksheet (name, ?fsRows, ?fsTables, ?fsCellsCollection) =
/// <summary>
/// Returns the FsRow at the given index. If it does not exist, it is created and appended first.
/// </summary>
member self.Row(rowIndex) =
member self.Row(rowIndex, ?SkipSearch) =
let skipSearch = defaultArg SkipSearch false
if skipSearch then
let row = FsRow.createAt(rowIndex,self.CellCollection)
_rows.Add row
row
else
match _rows |> Seq.tryFind (fun row -> row.Index = rowIndex) with
| Some row ->
row
Expand All @@ -150,7 +156,7 @@ type FsWorksheet (name, ?fsRows, ?fsTables, ?fsCellsCollection) =
if rangeAddress.FirstAddress.RowNumber <> rangeAddress.LastAddress.RowNumber then
failwithf "Row may not have a range address spanning over different row indices"
if skipSearch then
let row = FsRow.createAt(rangeAddress.FirstAddress.RowNumber,self.CellCollection)
let row = FsRow (rangeAddress, self.CellCollection)
row.RangeAddress <- rangeAddress
_rows.Add row
row
Expand Down
30 changes: 28 additions & 2 deletions tests/FsSpreadsheet.Tests/FsRowTests.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FsRow


open TestingUtils
#if FABLE_COMPILER
open Fable.Mocha
#else
Expand All @@ -17,7 +17,27 @@ let getDummyWorkSheet() =
worksheet.RescanRows()
worksheet

let main =

let performace =
testList "performance" [
testCase "FrowFromRange-SkipSearch" (fun () ->
let rowCount= 100000
let ws = FsWorksheet.init("MyWorksheet")
let timer = Stopwatch()
timer.Start()
for i = 1 to rowCount do
let address = FsRangeAddress(FsAddress(i,1), FsAddress(i,1))
ws.RowWithRange(address,true) |> ignore
timer.Stop()
let runtime = timer.Elapsed.Milliseconds
let expected = 50 // this is too high and should be reduced

Expect.equal ws.Rows.Count rowCount "Row count"
Expect.isTrue (runtime <= expected) $"Expected conversion to be finished in under {expected}, but it took {runtime}"
)
]

let rowOperations =
testList "rowOperations" [
testList "Prerequisites" [
let dummyWorkSheet = getDummyWorkSheet()
Expand Down Expand Up @@ -117,3 +137,9 @@ let main =
Expect.equal maxColIndex 1 "Incorrect index"
]
]

let main =
testList "FsRow" [
rowOperations
performace
]
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\FsSpreadsheet\FsSpreadsheet.fsproj" />
<ProjectReference Include="..\TestUtils\TestUtils.fsproj" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit fc5f16f

Please sign in to comment.