Created
July 4, 2018 17:48
-
-
Save mjs3339/3c3550349657210a5562a3b1523ddfeb to your computer and use it in GitHub Desktop.
C# - Calculates the GFLOPS Of A PC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double CalculateThisPCGFLOPS() | |
{ | |
const int Flops = 10_000_000; | |
const int Loops = 10; | |
var etl = new List<double>(); | |
var random = new Random(); | |
var begE1 = Enumerable.Range(0, Flops).AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount).Select(i => random.NextDouble()).ToArray(); | |
var mulE1 = Enumerable.Range(0, Flops).AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount).Select(i => random.NextDouble()).ToArray(); | |
for(var loop = 0; loop < Loops; ++loop) | |
{ | |
var begE = begE1; | |
var mulE = mulE1; | |
var th1 = new Thread(() => | |
{ | |
var timer = Stopwatch.StartNew(); | |
for(var i = 0; i < Flops - 1; i++) | |
begE[i] += mulE[i] * 3.14; | |
timer.Stop(); | |
begE = begE1; | |
mulE = mulE1; | |
timer = Stopwatch.StartNew(); | |
for(var i = 0; i < Flops - 1; i++) | |
begE[i] += mulE[i] * 3.14; | |
timer.Stop(); | |
etl.Add(timer.Elapsed.TotalMilliseconds); | |
}) | |
{ | |
Priority = ThreadPriority.Highest | |
}; | |
th1.Start(); | |
th1.Join(); | |
} | |
var at = Math.Round(Flops / etl.AverageEx() / 1000.0); | |
return at; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment