Benchmarks.cs 1.6 KB
Newer Older
1
using BenchmarkDotNet.Attributes;
2 3
using BenchmarkDotNet.Attributes.Columns;
using BenchmarkDotNet.Columns;
4 5
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
6 7 8 9
using BenchmarkDotNet.Horology;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Order;
using Dapper.Tests.Performance.Helpers;
10 11 12 13 14 15
using System;
using System.Configuration;
using System.Data.SqlClient;

namespace Dapper.Tests.Performance
{
16 17
    [OrderProvider(SummaryOrderPolicy.FastestToSlowest)]
    [RankColumn]
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
    [Config(typeof(Config))]
    public abstract class BenchmarkBase
    {
        public const int Iterations = 50;
        protected static readonly Random _rand = new Random();
        protected SqlConnection _connection;
        public static string ConnectionString { get; } = ConfigurationManager.ConnectionStrings["Main"].ConnectionString;
        protected int i;

        protected void BaseSetup()
        {
            i = 0;
            _connection = new SqlConnection(ConnectionString);
            _connection.Open();
        }

        protected void Step()
        {
            i++;
            if (i > 5000) i = 1;
        }
    }

    public class Config : ManualConfig
    {
        public Config()
        {
            Add(new MemoryDiagnoser());
46 47 48 49 50 51 52 53
            Add(new ORMColum());
            Add(new ReturnColum());
            Add(Job.Default
                .WithLaunchCount(1)
                .WithIterationTime(new TimeInterval(500, TimeUnit.Millisecond))
                .WithWarmupCount(3)
                .WithTargetCount(3)
            );
54 55 56
        }
    }
}