Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions tests/FSharp.Data.Benchmarks/JsonBenchmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,27 @@ type JsonConversionBenchmarks() =

[<Benchmark>]
member this.AccessProperties() =
sampleJson.Properties()
|> Array.head
|> fun (_, value) -> value
match sampleJson with
| JsonValue.Array elements when elements.Length > 0 ->
// Get properties of the first issue in the GitHub issues array
elements.[0].Properties()
|> Array.head
|> fun (_, value) -> value
| JsonValue.Record _ ->
// Fallback for record-type JSON
sampleJson.Properties()
|> Array.head
|> fun (_, value) -> value
| _ -> JsonValue.Null

[<Benchmark>]
member this.GetArrayElements() =
match sampleJson with
| JsonValue.Array elements ->
// GitHub.json is an array of issues, return the array elements
elements
| JsonValue.Record props ->
// Fallback: look for an "items" property
match Array.tryFind (fun (k, _) -> k = "items") props with
| Some (_, JsonValue.Array elements) -> elements
| _ -> [||]
Expand Down
Loading