1
1
open System
2
2
open System.Diagnostics
3
3
4
- // 16 byte struct
5
- [<Struct>]
6
- type Point2D ( x : double , y : double ) =
7
- member _.X = x
8
- member _.Y = y
9
4
10
5
// Will create a tail il instruction and force a tail call. This is will become
11
6
// a fast tail call on unix x64 as the caller and callee have equal stack size
12
7
let fifth () =
13
- let rec fifthMethodFirstCallee ( iterationCount , firstArg : Point2D , secondArg : Point2D , thirdArg : Point2D , fourthArg : Point2D , fifthArg : Point2D ) =
14
- if firstArg.X <> 10.0 then - 100
15
- else if firstArg.Y <> 20.0 then - 101
16
- else if secondArg.X <> 30.0 then - 102
17
- else if secondArg.Y <> 40.0 then - 103
18
- else if thirdArg.X <> 10.0 then - 104
19
- else if thirdArg.Y <> 20.0 then - 105
20
- else if fourthArg.X <> 30.0 then - 106
21
- else if fourthArg.Y <> 40.0 then - 107
22
- else if fifthArg.X <> 10.0 then - 108
23
- else if fifthArg.Y <> 20.0 then - 109
24
- else if iterationCount = 0 then
8
+ let rec fifthMethodFirstCallee ( iterationCount , firstArg : int ) =
9
+ if iterationCount = 0 then
25
10
100
26
11
else if iterationCount % 2 = 0 then
27
- fifthMethodSecondCallee( iterationCount - 1 , firstArg, secondArg , thirdArg , fourthArg , fifthArg )
12
+ fifthMethodSecondCallee( iterationCount - 1 , firstArg)
28
13
else
29
- fifthMethodFirstCallee( iterationCount - 1 , firstArg, secondArg , thirdArg , fourthArg , fifthArg )
14
+ fifthMethodFirstCallee( iterationCount - 1 , firstArg)
30
15
31
- and fifthMethodSecondCallee ( iterationCount , firstArg , secondArg , thirdArg , fourthArg , fifthArg ) =
32
- if firstArg.X <> 10.0 then - 150
33
- else if firstArg.Y <> 20.0 then - 151
34
- else if secondArg.X <> 30.0 then - 152
35
- else if secondArg.Y <> 40.0 then - 153
36
- else if thirdArg.X <> 10.0 then - 154
37
- else if thirdArg.Y <> 20.0 then - 155
38
- else if fourthArg.X <> 30.0 then - 156
39
- else if fourthArg.Y <> 40.0 then - 157
40
- else if fifthArg.X <> 10.0 then - 158
41
- else if fifthArg.Y <> 20.0 then - 159
42
- else if iterationCount = 0 then
16
+ and fifthMethodSecondCallee ( iterationCount , firstArg ) =
17
+ if iterationCount = 0 then
43
18
101
44
19
else if iterationCount % 2 = 0 then
45
- fifthMethodSecondCallee( iterationCount - 1 , firstArg, secondArg , thirdArg , fourthArg , fifthArg )
20
+ fifthMethodSecondCallee( iterationCount - 1 , firstArg)
46
21
else
47
- fifthMethodFirstCallee( iterationCount - 1 , firstArg, secondArg , thirdArg , fourthArg , fifthArg )
22
+ fifthMethodFirstCallee( iterationCount - 1 , firstArg)
48
23
49
- let point = Point2D( 10.0 , 20.0 )
50
- let secondPoint = Point2D( 30.0 , 40.0 )
51
24
52
- let retVal = fifthMethodFirstCallee( 1000000 , point, secondPoint, point, secondPoint, point)
53
25
54
- if retVal <> 100 && retVal <> 101 then
55
- printfn " Method -- Failed, expected result: 100 or 101, calculated: %d " retVal
56
- - 5
57
- else
58
- 0
26
+ fifthMethodFirstCallee( 1000000 , 158_423 )
27
+
59
28
60
29
[<EntryPoint>]
61
30
let main argv =
62
- let startTime = Stopwatch.StartNew()
63
- for i in 0 .. 100 do
64
- ignore ( fifth ())
65
- let elapsedTime = startTime.Elapsed.TotalMilliseconds
66
- printfn " %f ms" elapsedTime
67
- 0
31
+ fifth ()
0 commit comments