-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (85 loc) · 2.94 KB
/
Program.cs
File metadata and controls
87 lines (85 loc) · 2.94 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
77
78
79
80
81
82
83
84
85
86
87
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Text.RegularExpressions;
namespace Less3
{
class Program
{
static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
}
public class BechmarkClass
{
public static float PointDistanceS(PointStruct pointOne, PointStruct pointTwo)
{
float x = pointOne.X - pointTwo.X;
float y = pointOne.Y - pointTwo.Y;
return MathF.Sqrt((x * x) + (y * y));
}
public static float PointDistanceC(PointClass pointOne, PointClass pointTwo)
{
float x = pointOne.X - pointTwo.X;
float y = pointOne.Y - pointTwo.Y;
return MathF.Sqrt((x * x) + (y * y));
}
public static float PointDistanceShort(PointStruct pointOne, PointStruct pointTwo)
{
float x = pointOne.X - pointTwo.X;
float y = pointOne.Y - pointTwo.Y;
return (x * x) + (y * y);
}
public static double PointDistanceDouble(PointStruct pointOne, PointStruct pointTwo)
{
double x = pointOne.X - pointTwo.X;
double y = pointOne.Y - pointTwo.Y;
return Math.Sqrt((x * x) + (y * y));
}
public static PointClass giveMeThis()
{
var rnd = new Random();
double xD = rnd.NextDouble();
double yD = rnd.NextDouble();
PointClass point = new PointClass()
{
X = (float)xD,
Y = (float)yD
};
return point;
}
public static PointStruct giveMeThat()
{
var rnd = new Random();
double xD = rnd.NextDouble();
double yD = rnd.NextDouble();
PointStruct point = new PointStruct()
{
X = (float) xD,
Y = (float) yD
};
return point;
}
[Benchmark(Description = "Расстояние через классы, переменные тип float" )]
public void RunTest1()
{
PointDistanceC(giveMeThis(), giveMeThis());
}
[Benchmark(Description = "Расстояние через структуры, переменные тип float")]
public void RunTest2()
{
PointDistanceS(giveMeThat(), giveMeThat());
}
[Benchmark(Description = "Расстояние через структуры, переменные тип double")]
public void RunTest3()
{
PointDistanceDouble(giveMeThat(), giveMeThat());
}
[Benchmark(Description = "Упрощенный расчет через структуры, переменные тип float")]
public void RunTest4()
{
PointDistanceDouble(giveMeThat(), giveMeThat());
}
}
}