Skip to content

Commit

Permalink
first draft of performanceReport target
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 18, 2024
1 parent d64e708 commit 41fef58
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 171 deletions.
29 changes: 29 additions & 0 deletions build/TestTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ module RunTests =
|> Seq.iter dotnetRun
}


module PerformanceReport =

let cpu =
Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\SYSTEM\\CentralProcessor\\0", "ProcessorNameString", null) :?> string

let testPerformancePy = BuildTask.create "testPerformancePy" [clean; build] {
let path = "tests/TestingUtils"
//transpile py files from fsharp code
run dotnet $"fable {path} -o {path}/py --lang python" ""
// run pyxpecto in target path to execute tests in python
run python $"{path}/py/performance_report.py {cpu}" ""
}
let testPerformanceJs = BuildTask.create "testPerformanceJS" [clean; build] {
let path = "tests/TestingUtils"
// transpile js files from fsharp code
run dotnet $"fable {path} -o {path}/js" ""
// run mocha in target path to execute tests
run npx $"mocha {path}/js {cpu}" ""
}
let testPerformanceDotnet = BuildTask.create "testPerformanceDotnet" [clean; build] {
let path = "tests/TestingUtils"
run dotnet $"run --project {path} {cpu}" ""
}

let perforanceReport = BuildTask.create "PerformanceReport" [PerformanceReport.testPerformancePy; PerformanceReport.testPerformanceJs; PerformanceReport.testPerformanceDotnet] {
()
}

let runTests = BuildTask.create "RunTests" [clean; build; RunTests.runTestsJs; RunTests.runTestsJsNative; RunTests.runTestsPy; RunTests.runTestsDotnet] {
()
}
48 changes: 0 additions & 48 deletions tests/ISA/ISA.Json.Tests/ArcTypes.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,6 @@ let tests_ArcTable = testList "ArcTable" [
let decoded = ArcTable.fromCompressedJsonString encoded
Expect.equal decoded filled "empty table is wrong after compressed encoding and decoding"
// Set to pTest in Fable, as compressed parsing is around 10times slower than uncompressed parsing. This is weird, since in dotnet it is around 10times faster
#if FABLE_COMPILER
ptestCase "Performance" <| fun _ ->
#else
testCase "Performance" <| fun _ ->
#endif
let t = TestObjects.Spreadsheet.Study.LargeFile.table
Expect.isFasterThan (t.ToCompressedJsonString >> ignore) (t.ToJsonString >> ignore) "toCompressedJsonString is slower than to uncompressed"
let json = t.ToJsonString()
let compressed = Expect.wantFaster (t.ToCompressedJsonString) 1000 "toCompressedJsonString should be faster"
Expect.isTrue (compressed.Length*5 < json.Length) $"compressed should be more than 10 times smaller than uncompressed, but was only {float json.Length / float compressed.Length}x smaller"
testCase "rangeColumnSize" <| fun _ ->
// testTable column should be saved as range column, this should make it smaller than the IO column even though it has more cells
let testTable = ArcTable.init("Test")
Expand Down Expand Up @@ -258,44 +248,6 @@ let tests_ArcAssay = testList "ArcAssay" [
let decoded = ArcAssay.fromCompressedJsonString encoded
Expect.equal decoded filled "empty table is wrong after compressed encoding and decoding"
]
testList "performance" [
testCase "SingleLongTable_JsonAssay" <| fun _ ->
let a = ArcAssay.init("MyAssay")
let t = a.InitTable("MyTable")
t.AddColumn(CompositeHeader.Input IOType.Source)
t.AddColumn(CompositeHeader.Parameter (OntologyAnnotation.fromString("MyParameter1")))
t.AddColumn(CompositeHeader.Parameter (OntologyAnnotation.fromString("MyParameter2")))
t.AddColumn(CompositeHeader.Parameter (OntologyAnnotation.fromString("MyParameter3")))
t.AddColumn(CompositeHeader.Characteristic (OntologyAnnotation.fromString("MyCharacteristic")))
t.AddColumn(CompositeHeader.Output IOType.Sample)
let rowCount = 10000
for i = 0 to rowCount - 1 do
let cells =
[|
CompositeCell.FreeText $"Source{i}"
CompositeCell.FreeText $"Parameter1_value"
CompositeCell.FreeText $"Parameter2_value"
CompositeCell.FreeText $"Parameter3_value{i - i % 10}"
CompositeCell.FreeText $"Characteristic_value"
CompositeCell.FreeText $"Sample{i}"
|]
for j = 0 to cells.Length - 1 do
t.Values.[(j,i)] <- cells.[j]
let f() = ArcAssay.toJsonString a
#if FABLE_COMPILER_JAVASCRIPT
let expectedMs = 5000
#endif
#if FABLE_COMPILER_PYTHON
let expectedMs = 100000
#endif
#if !FABLE_COMPILER
let expectedMs = 2500
#endif
// 1200ms in Dotnet on i7-13800H
// 3412ms in Javascript on i7-13800H
// 24562ms in Javascript on i7-13800H
Expect.wantFaster f expectedMs "toJsonString should be faster" |> ignore
]
]

let tests_ArcStudy = testList "ArcStudy" [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<Compile Include="StudyFileTests.fs" />
<Compile Include="AssayFileTests.fs" />
<Compile Include="InvestigationFileTests.fs" />
<Compile Include="Performance.Tests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion tests/ISA/ISA.Spreadsheet.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ let all = testSequenced <| testList "ISA.Spreadsheet" [
ArcStudyTests.main
SparseTableTests.main
IdentifierTests.main
Tests.Performance.Main
]

[<EntryPoint>]
Expand Down
45 changes: 0 additions & 45 deletions tests/ISA/ISA.Spreadsheet.Tests/Performance.Tests.fs

This file was deleted.

79 changes: 3 additions & 76 deletions tests/ISA/ISA.Tests/ArcTable.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ let private tests_GetHashCode = testList "GetHashCode" [
let notActual = create_testTable()
Expect.notEqual actual notActual "equal"
Expect.notEqual (actual.GetHashCode()) (notActual.GetHashCode()) "Hash"
testCase "Performance" <| fun _ ->
let testTable = ArcTable.init("Test")
let values = Array.init 10000 (fun i -> CompositeCell.createFreeText (string i))
testTable.AddColumn(CompositeHeader.FreeText "Header", values)
let f1 () = testTable.GetHashCode()
#if FABLE_COMPILER_PYTHON
let expectedMs = 500
#else
let expectedMs = 50
#endif
// On i7-13800H, 2ms in Dotnet and 18ms in javascript
Expect.wantFaster f1 expectedMs "GetHashCode is too slow" |> ignore
]

let private tests_validate =
Expand Down Expand Up @@ -483,29 +471,6 @@ let private tests_UpdateCell =
let eval() = table.UpdateCellAt(0,0,cell)
Expect.throws eval ""
)

// Commented this test out, as the behaviour is different in dotnet and js, but both implementations are very close together performance-wise

//testCase "performance" (fun () ->
// // Test, that for most cases (because of performance), setter should be used
// let f1 = fun () ->
// let table = ArcTable.init("Table")
// for i = 0 to 10 do
// table.Headers.Insert(i,CompositeHeader.FreeText $"Header_{i}")
// for j = 0 to 5000 do
// ArcTableAux.Unchecked.setCellAt(i,j,CompositeCell.createFreeText $"Cell_{i}_{j}") table.Values
// let f2 = fun () ->
// let table = ArcTable.init("Table")
// for i = 0 to 10 do
// table.Headers.Insert(i,CompositeHeader.FreeText $"Header_{i}")
// for j = 0 to 5000 do
// ArcTableAux.Unchecked.addCellAt(i,j,CompositeCell.createFreeText $"Cell_{i}_{j}") table.Values
// Expect.isFasterThan f1 f2 "SetCell Implementation should be faster than reference"



//)

]

let private tests_UpdateColumn =
Expand Down Expand Up @@ -2023,19 +1988,6 @@ let private tests_AddRows =
else
Expect.equal table.Values.[columnIndex, rowIndex] newTable.Values.[columnIndex, rowIndex-newColumnCount] $"Cell {columnIndex},{rowIndex}"
)
testCase "performance" (fun () ->
let table = ArcTable("MyTable",ResizeArray [CompositeHeader.Input IOType.Sample;CompositeHeader.FreeText "Freetext1" ; CompositeHeader.FreeText "Freetext2"; CompositeHeader.Output IOType.Sample], System.Collections.Generic.Dictionary())
let rows =
Array.init 10000 (fun i ->
[|CompositeCell.FreeText $"Source_{i}"; CompositeCell.FreeText $"FT1_{i}"; CompositeCell.FreeText $"FT2_{i}"; CompositeCell.FreeText $"Sample_{i}"; |])
let testF = fun () -> table.AddRows(rows)
#if FABLE_COMPILER_PYTHON
let expectedMs = 1000
#else
let expectedMs = 100
#endif
Expect.wantFaster testF expectedMs $"AddRows is too slow." |> ignore
)
]

let private tests_UpdateRefWithSheet =
Expand Down Expand Up @@ -2316,34 +2268,9 @@ let private tests_equality = testList "equality" [
]


let private tests_fillMissing = testList "fillMissing" [
testCase "performance" <| fun _ ->

let headers = ResizeArray [CompositeHeader.Input IOType.Sample;CompositeHeader.FreeText "Freetext1" ; CompositeHeader.FreeText "Freetext2"; CompositeHeader.Output IOType.Sample]
let values = System.Collections.Generic.Dictionary()
for i = 0 to 20000 do
if i%2 = 0 then
ArcTableAux.Unchecked.setCellAt(0,i,(CompositeCell.FreeText $"Source_{i}")) values
ArcTableAux.Unchecked.setCellAt(1,i,(CompositeCell.FreeText $"FT1_{i}")) values
ArcTableAux.Unchecked.setCellAt(2,i,(CompositeCell.FreeText $"FT2_{i}")) values
ArcTableAux.Unchecked.setCellAt(3,i,(CompositeCell.FreeText $"FT3_{i}")) values
ArcTableAux.Unchecked.setCellAt(6,i,(CompositeCell.FreeText $"Sample_{i}")) values
else
ArcTableAux.Unchecked.setCellAt(0,i,(CompositeCell.FreeText $"Source_{i}")) values
ArcTableAux.Unchecked.setCellAt(3,i,(CompositeCell.FreeText $"FT3_{i}")) values
ArcTableAux.Unchecked.setCellAt(4,i,(CompositeCell.FreeText $"FT4_{i}")) values
ArcTableAux.Unchecked.setCellAt(5,i,(CompositeCell.FreeText $"FT5_{i}")) values
ArcTableAux.Unchecked.setCellAt(6,i,(CompositeCell.FreeText $"Sample_{i}")) values
let testF = fun () -> ArcTableAux.Unchecked.fillMissingCells headers values
#if FABLE_COMPILER_PYTHON
let expectedMs = 10000
#else
let expectedMs = 220
#endif
//4800ms in python on i7-13800H
Expect.wantFaster testF expectedMs "fillMissing is too slow." |> ignore // 130ms in javascript, dotnet faster than 100ms
]
//let private tests_fillMissing = testList "fillMissing" [

// ]

let main =
testList "ArcTable" [
Expand All @@ -2368,5 +2295,5 @@ let main =
tests_IterColumns
tests_GetHashCode
tests_equality
tests_fillMissing
//tests_fillMissing
]
Loading

0 comments on commit 41fef58

Please sign in to comment.