Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save badamczewski/bf9252b6c1ddbdc7fb6140663ff7d571 to your computer and use it in GitHub Desktop.
Save badamczewski/bf9252b6c1ddbdc7fb6140663ff7d571 to your computer and use it in GitHub Desktop.
Conditions.cs
[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