Skip to content

Instantly share code, notes, and snippets.

@relyky
Last active July 27, 2021 15:39
Show Gist options
  • Save relyky/886e7fa433ed7c89c16bfc42715ca2c0 to your computer and use it in GitHub Desktop.
Save relyky/886e7fa433ed7c89c16bfc42715ca2c0 to your computer and use it in GitHub Desktop.
Benchmark sample, BenchmarkDotNet
///
/// BenchmarkDotNet v0.13.0
/// ref→[Getting started](https://benchmarkdotnet.org/articles/guides/getting-started.html)
///
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
class Program
{
static void Main(string[] args)
{
/// 測試進入點
BenchmarkRunner.Run<TestCase>();
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}
/// 測試邏輯
public class TestCase
{
[Benchmark]
public void TestMethod1()
{
var t = new Fin();
int ret = t.fin(35);
}
[Benchmark]
public void TestMethod2()
{
var t = new Fin();
int ret = t.fin(15);
}
}
/// 測試標的,正式情況下應該做成 Library。
public class Fin
{
public int fin(int n)
{
return n <= 0 ? 0 : n + fin(n - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment