-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVector.fs
More file actions
68 lines (52 loc) · 1.95 KB
/
Copy pathVector.fs
File metadata and controls
68 lines (52 loc) · 1.95 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
namespace FsMath.Benchmarks
open System
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open FsMath
[<MemoryDiagnoser>]
type VectorBenchmarks() =
let mutable vector1 = [||]
let mutable vector2 = [||]
// Parameterize vector sizes
[<Params(10, 100, 1000, 10000)>]
member val Size = 0 with get, set
[<GlobalSetup>]
member this.Setup() =
vector1 <- Array.init this.Size (fun i -> float i)
vector2 <- Array.init this.Size (fun i -> float (i * 2))
[<Benchmark>]
member _.Add() =
let result = Vector.add vector1 vector2
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Sub() =
let result = Vector.subtract vector1 vector2
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Multiply() =
let result = Vector.multiply vector1 vector2
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.DotProduct() =
let result = Vector.dot vector1 vector2
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Norm() =
let result = Vector.norm vector1
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Sum() =
let result = Vector.sum vector1
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Product() =
let result = Vector.product vector1
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Min() =
let result = Vector.min vector1
GC.KeepAlive(result) // Prevents the result from being optimized away
[<Benchmark>]
member _.Max() =
let result = Vector.max vector1
GC.KeepAlive(result) // Prevents the result from being optimized away