Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MathMaxBenchmarks
- {
- private static double[] _testInput;
- [GlobalSetup]
- public void Setup()
- {
- _testInput = Enumerable.Range(0, 10000).Select(i => (double)i).ToArray();
- }
- [Benchmark(Baseline = true)]
- public double[] MathMax()
- {
- double[] output = new double[_testInput.Length];
- for (var i = 0; i < _testInput.Length; i++)
- output[i] = Math.Max(_testInput[i], 100);
- return output;
- }
- [Benchmark]
- public double[] Ternary()
- {
- double[] output = new double[_testInput.Length];
- for (var i = 0; i < _testInput.Length; i++)
- {
- double tmp = _testInput[i];
- output[i] = tmp > 100.0 ? tmp : 100.0;
- }
- return output;
- }
- [Benchmark]
- public double[] vmaxsd()
- {
- var limit = Vector128.Create(100.0);
- double[] output = new double[_testInput.Length];
- for (var i = 0; i < _testInput.Length; i++)
- output[i] = Sse2.MaxScalar(Vector128.CreateScalarUnsafe(_testInput[i]), limit).ToScalar();
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement