-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathHttpBenchmarks.fs
More file actions
76 lines (66 loc) · 2.46 KB
/
HttpBenchmarks.fs
File metadata and controls
76 lines (66 loc) · 2.46 KB
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
namespace FSharp.Data.Benchmarks
open System
open System.Net
open BenchmarkDotNet.Attributes
open FSharp.Data
[<MemoryDiagnoser>]
[<SimpleJob>]
type HttpBenchmarks() =
// Use public HTTP test endpoints for realistic benchmarks
let httpBinUrl = "https://httpbin.org"
let smallEndpoint = $"{httpBinUrl}/get"
let jsonEndpoint = $"{httpBinUrl}/json"
[<Benchmark>]
member _.SingleHttpBinRequest() =
try
Http.RequestString(smallEndpoint, timeout = 5000)
with
| :? WebException -> "Network error" // Handle network issues in CI
[<Benchmark>]
member _.HttpBinJsonRequest() =
try
Http.RequestString(jsonEndpoint, timeout = 5000)
with
| :? WebException -> "Network error" // Handle network issues in CI
[<Benchmark>]
member _.MultipleSequentialRequests() =
for _ in 1..3 do
try
Http.RequestString(smallEndpoint, timeout = 5000) |> ignore
with
| :? WebException -> () // Handle network issues in CI
[<Benchmark>]
member _.PostRequest() =
let body = TextRequest "test data"
try
Http.RequestString($"{httpBinUrl}/post", httpMethod = "POST", body = body, timeout = 5000)
with
| :? WebException -> "Network error" // Handle network issues in CI
[<Benchmark>]
member _.RequestWithHeaders() =
let headers = [("User-Agent", "FSharp.Data.Benchmarks"); ("Accept", "application/json")]
try
Http.RequestString(smallEndpoint, headers = headers, timeout = 5000)
with
| :? WebException -> "Network error" // Handle network issues in CI
[<Benchmark>]
member _.TypeProviderWorkloadSimulation() =
// Simulate a type provider fetching sample data and caching
for _ in 1..2 do
try
Http.RequestString(jsonEndpoint, timeout = 5000) |> ignore
with
| :? WebException -> () // Handle network issues in CI
[<Benchmark>]
member _.MultipleConnectionsToSameHost() =
// Test connection reuse with keep-alive optimization
let endpoints = [
$"{httpBinUrl}/get"
$"{httpBinUrl}/json"
$"{httpBinUrl}/user-agent"
]
for endpoint in endpoints do
try
Http.RequestString(endpoint, timeout = 5000) |> ignore
with
| :? WebException -> () // Handle network issues in CI