You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
3.0 KiB
C#

<EFBFBD><EFBFBD>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 <EFBFBD>W<EFBFBD>QKmՋ
/// </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($"<00>e<EFBFBD>l<EFBFBD>~_g<5F>e<1A>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());
}
}
}