Created
April 20, 2021 09:28
-
-
Save badamczewski/bf9252b6c1ddbdc7fb6140663ff7d571 to your computer and use it in GitHub Desktop.
Conditions.cs
This file contains hidden or 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
[IterationCount(10)] | |
[InvocationCount(100_000_000)] | |
public class Bench22 | |
{ | |
Random rnd = new Random(); | |
private int x; | |
public int X | |
{ | |
get { return rnd.Next(1, 5); } | |
} | |
[Benchmark] | |
[Arguments(1)] | |
[Arguments(2)] | |
[Arguments(3)] | |
[Arguments(4)] | |
public int CSharp(int s) | |
{ | |
return Cond(s); | |
} | |
[Benchmark] | |
[Arguments(1)] | |
[Arguments(2)] | |
[Arguments(3)] | |
[Arguments(4)] | |
public int FSharp(int s) | |
{ | |
return FSTest.Bench.condition(s); | |
} | |
// | |
// FSharp will not inline the code so we shouldn't eiter. | |
// | |
[MethodImpl(MethodImplOptions.NoInlining)] | |
public static int Cond(int x) | |
{ | |
if (x == 1 || x == 2) return 1; | |
else if (x == 3 || x == 4) return 2; | |
else return 0; | |
} | |
} | |
//// FS CODE | |
// | |
// | |
/* | |
namespace FSTest | |
module Bench = | |
let condition x = | |
if (x = 1 || x = 2) then 1 | |
elif(x = 3 || x = 4) then 2 | |
else 0 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment