using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using BenchmarkDotNet;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;

using BenchMarkDotnetStudy.Core;

namespace BenchMarkDotnetStudy.BenchmarkStudy
{
    /// <summary>
    /// Counter 基准测试
    /// </summary>
    [SimpleJob(runtimeMoniker:RuntimeMoniker.Net70)]
    [SimpleJob(runtimeMoniker:RuntimeMoniker.NativeAot70)]
    [MemoryDiagnoser]
    [ThreadingDiagnoser]
    public class CounterTest3
    {
        [Benchmark]
        public void Thread2_Test()
        {
            Counter counter = new Counter();

            List<Thread> threads = new List<Thread>()
            {
                new Thread(() => counter.Increment() ),
                new Thread(() => counter.Increment() ),
            };


            threads.ForEach(t => t.Start());
            threads.ForEach(t => t.Join());

            //Console.WriteLine($"方法结束时:TotalCounter = {Counter.TotalCounter}");
        }

        [Benchmark]
        public void Thread2_Test2()
        {
            Counter counter = new Counter();

            List<Thread> threads = new List<Thread>()
            {
                new Thread(() => counter.IncrementWithInterlocked() ),
                new Thread(() => counter.IncrementWithInterlocked() ),
            };


            threads.ForEach(t => t.Start());
            threads.ForEach(t => t.Join());
        }
    }
}