diff --git a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Benchmarks.cs b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Benchmarks.cs index 0ea75aa10..3bfe9f631 100644 --- a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Benchmarks.cs +++ b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Benchmarks.cs @@ -3,6 +3,7 @@ namespace Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests; +[MarkdownExporter, AsciiDocExporter, HtmlExporter] [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)] [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)] [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)] @@ -10,45 +11,49 @@ namespace Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests; public class Benchmarks { private IIdGenerator _idGenerator; + private IIdGenerator _idGeneratorBySecond; + private IIdGenerator _idGeneratorByEnableMachineClock; + private IIdGenerator _idGeneratorBySecondAndEnableMachineClock; [GlobalSetup] public void GlobalSetup() { - IServiceCollection services = new ServiceCollection(); - services.AddSnowflake(); - var serviceProvider = services.BuildServiceProvider(); - _idGenerator = serviceProvider.GetRequiredService>(); - _idGenerator.NewId(); + _idGenerator = InitializeIdGenerator(services => services.AddSnowflake()); + _idGeneratorBySecond = + InitializeIdGenerator(services => services.AddSnowflake(options => options.TimestampType = TimestampType.Seconds)); + _idGeneratorByEnableMachineClock = + InitializeIdGenerator(services => services.AddSnowflake(options => options.EnableMachineClock = true)); + _idGeneratorBySecondAndEnableMachineClock = + InitializeIdGenerator(services => services.AddSnowflake(options => + { + options.EnableMachineClock = true; + options.TimestampType = TimestampType.Seconds; + })); } - [Benchmark] - public void SnowflakeByMillisecond() - { - _idGenerator.NewId(); - } -} - -[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)] -[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)] -[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)] -[MinColumn, MaxColumn, MeanColumn, MedianColumn] -public class SecondBenchmarks -{ - private IIdGenerator _idGenerator; - - [GlobalSetup] - public void GlobalSetup() + private IIdGenerator InitializeIdGenerator(Action action) { IServiceCollection services = new ServiceCollection(); - services.AddSnowflake(options => options.TimestampType = TimestampType.Seconds); + action.Invoke(services); var serviceProvider = services.BuildServiceProvider(); - _idGenerator = serviceProvider.GetRequiredService>(); - _idGenerator.NewId(); + var idGenerator = serviceProvider.GetRequiredService>(); + idGenerator.NewId(); + return idGenerator; } + [Benchmark(Baseline = true)] + public void SnowflakeByMillisecond() + => _idGenerator.NewId(); + [Benchmark] public void SnowflakeBySecond() - { - _idGenerator.NewId(); - } + => _idGeneratorBySecond.NewId(); + + [Benchmark] + public void SnowflakeByMillisecondAndEnableMachineClock() + => _idGeneratorByEnableMachineClock.NewId(); + + [Benchmark] + public void SnowflakeBySecondAndEnableMachineClock() + => _idGeneratorBySecondAndEnableMachineClock.NewId(); } diff --git a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/DistributedBenchmarks.cs b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/DistributedBenchmarks.cs index 4c3f9fd90..f0935150d 100644 --- a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/DistributedBenchmarks.cs +++ b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/DistributedBenchmarks.cs @@ -3,40 +3,43 @@ namespace Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests; +/// +/// Only supports the use of Redis environment +/// [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)] [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)] [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)] [MinColumn, MaxColumn, MeanColumn, MedianColumn] public class DistributedBenchmarks { - private IIdGenerator _idGenerator; + // private IIdGenerator _idGenerator; - [GlobalSetup] - public void GlobalSetup() - { - IServiceCollection services = new ServiceCollection(); - services.AddMasaRedisCache(opt => - { - opt.Password = ""; - opt.DefaultDatabase = 2; - opt.Servers = new List() - { - new("127.0.0.1", 6379) - }; - }); - services.AddSnowflake(options => - { - options.UseRedis(); - options.EnableMachineClock = true; - }); - var serviceProvider = services.BuildServiceProvider(); - _idGenerator = serviceProvider.GetRequiredService>(); - _idGenerator.NewId(); - } - - [Benchmark] - public void Distributed() - { - _idGenerator.NewId(); - } + // [GlobalSetup] + // public void GlobalSetup() + // { + // IServiceCollection services = new ServiceCollection(); + // services.AddMasaRedisCache(opt => + // { + // opt.Password = ""; + // opt.DefaultDatabase = 2; + // opt.Servers = new List() + // { + // new("127.0.0.1", 6379) + // }; + // }); + // services.AddSnowflake(options => + // { + // options.UseRedis(); + // options.EnableMachineClock = true; + // }); + // var serviceProvider = services.BuildServiceProvider(); + // _idGenerator = serviceProvider.GetRequiredService>(); + // _idGenerator.NewId(); + // } + // + // [Benchmark] + // public void Distributed() + // { + // _idGenerator.NewId(); + // } } diff --git a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/MachineClockBenchmarks.cs b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/MachineClockBenchmarks.cs deleted file mode 100644 index 95f4ff33d..000000000 --- a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/MachineClockBenchmarks.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the MIT License. See LICENSE.txt in the project root for license information. - -namespace Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests; - -[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)] -[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)] -[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)] -[MinColumn, MaxColumn, MeanColumn, MedianColumn] -public class MachineClockBenchmarks -{ - private IIdGenerator _idGenerator; - - [GlobalSetup] - public void GlobalSetup() - { - IServiceCollection services = new ServiceCollection(); - services.AddSnowflake(options => options.EnableMachineClock = true); - var serviceProvider = services.BuildServiceProvider(); - _idGenerator = serviceProvider.GetRequiredService>(); - _idGenerator.NewId(); - } - - [Benchmark] - public void MachineClockByMillisecond() - { - _idGenerator.NewId(); - } -} diff --git a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Program.cs b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Program.cs index f4c8ad106..178a1766a 100644 --- a/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Program.cs +++ b/test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Program.cs @@ -10,9 +10,7 @@ static void Main(string[] args) var config = DefaultConfig.Instance .AddValidator(ExecutionValidator.FailOnError) .WithOptions(ConfigOptions.DisableOptimizationsValidator); - // BenchmarkRunner.Run(config); - // BenchmarkRunner.Run(config); - BenchmarkRunner.Run(config); + BenchmarkRunner.Run(config); // BenchmarkRunner.Run(config); Console.ReadLine(); } diff --git a/test/Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests/Benchmarks.cs b/test/Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests/Benchmarks.cs index 0789cfdbc..2320cdf25 100644 --- a/test/Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests/Benchmarks.cs +++ b/test/Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests/Benchmarks.cs @@ -3,6 +3,7 @@ namespace Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests; +[MarkdownExporter, AsciiDocExporter, HtmlExporter] [SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100)] [MinColumn, MaxColumn, MeanColumn, MedianColumn] public class Benchmarks @@ -35,7 +36,7 @@ public void GlobalSetup() }; } - [Benchmark] + [Benchmark(Baseline = true)] public async Task SendCouponByDirect() { var _couponHandler = new CouponHandler(_serviceProvider);