-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProgram.cs
More file actions
88 lines (85 loc) · 3.37 KB
/
Program.cs
File metadata and controls
88 lines (85 loc) · 3.37 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
88
using System;
using System.Numerics;
using System.Collections.Generic;
using System.Diagnostics;
namespace BenchMarkDebug
{
class Program
{
static long[] longArray;
static long[] outLongArray;
static int longSlots = Vector<long>.Count;
static Stopwatch sw;
static void Main(string[] args)
{
Console.WriteLine($"Hardware Accelerated: {Vector.IsHardwareAccelerated}\n");
sw = new Stopwatch();
sw.Start();
Mandelbrot mn = new Mandelbrot();
Console.WriteLine($"Calculating Mandelbrot using floats");
long dt = sw.ElapsedMilliseconds;
int[] floatRes = mn.CalcFloat();
dt = sw.ElapsedMilliseconds - dt;
Console.WriteLine($"Finished in {dt}ms");
Console.WriteLine($"Calculating Mandelbrot using float vectors");
dt = sw.ElapsedMilliseconds;
int[] floatVecRes = mn.CalcVectorFloat();
dt = sw.ElapsedMilliseconds - dt;
Console.WriteLine($"Finished in {dt}ms");
Console.WriteLine($"Comparing results");
int differences = 0;
List<int> diffLocations = new List<int>();
if (mn.HasAllResults)
{
for(int i = 0; i < floatRes.Length; i++)
{
if(floatRes[i] != floatVecRes[i])
{
//Console.WriteLine($"\tFound difference in {i}th element (of {floatRes.Length}): {floatRes[i]} x {floatVecRes[i]} Stopped comparing.");
differences++;
diffLocations.Add(i);
//break;
}
}
Console.Write($"\tFinished comparing, found {differences} differences");
if(differences > 0)
{
Console.Write($"Starting at {diffLocations[0]}: \n");
/*foreach(int d in diffLocations)
{
Console.Write($"{d} ");
}*/
Console.Write("\n");
}
else
{
Console.Write("\n");
}
}
Console.WriteLine($"Done.");
//longArray = new long[1000];
//outLongArray = new long[longArray.Length / 2];
//MixedVectorLong();
Console.ReadLine();
}
static void MixedVectorLong()
{
//float sum = 0.0f;
//outFloatArray = new float[ITEMS / 2];
//Span<int> locSpan = intArray;
//Span<int> locOutSpan = outIntArray;
Vector<long> two = new Vector<long>(2);
int j = 0;
for (int i = 0; i < longArray.Length; i += 2 * longSlots)
{
//outFloatArray[j] += (float) Math.Sqrt((floatArray[i] * floatArray[i + 1]) / 2.0);
Vector<long> first = new Vector<long>(longArray, i);
Vector<long> second = new Vector<long>(longArray, i + longSlots);
Vector<long> res = first * second;// / two;
res.CopyTo(outLongArray, j);
//(Vector.SquareRoot(new Vector<long>(longArray, i) * new Vector<long>(longArray, i + longSlots)) /two).CopyTo(outLongArray, j);
j += longSlots;
}
}
}
}