-
-
Notifications
You must be signed in to change notification settings - Fork 457
Expand file tree
/
Copy pathFloorBenchmark.cs
More file actions
53 lines (46 loc) · 1.24 KB
/
FloorBenchmark.cs
File metadata and controls
53 lines (46 loc) · 1.24 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
namespace Silk.NET.Maths.Benchmark
{
[SimpleJob(RunStrategy.Throughput)]
public class FloorBenchmark
{
[ParamsSource("GenerateNumber")] public float X;
public int XInt;
[GlobalSetup]
public void GlobalSetup()
{
XInt = (int)X;
}
[Benchmark(Baseline = true)]
public float Sys()
{
#if MATHF
return MathF.Floor(X);
#else
return (float)Math.Floor(X);
#endif
}
[Benchmark]
public float SilkFloat()
{
return Scalar.Floor(X);
}
[Benchmark]
public int SilkInt()
{
return Scalar.Floor(XInt);
}
private const int NumbersTested = 1;
private static Random _random = new Random();
public IEnumerable<float> GenerateNumber()
{
for (int i = 0; i < NumbersTested; i++)
yield return (float) _random.NextDouble();
}
}
}