Skip to content

Commit 1434e65

Browse files
authored
chore: update benchmark (#124)
* feat(Storage): Add AddAliyunStorage to support asynchronous * Doc(Storage): Asynchronous support * doc(Storage): Modify Storage README * chore: Update Benchmark
1 parent a840ee2 commit 1434e65

File tree

5 files changed

+68
-90
lines changed

5 files changed

+68
-90
lines changed

test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Benchmarks.cs

+33-28
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,57 @@
33

44
namespace Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests;
55

6+
[MarkdownExporter, AsciiDocExporter, HtmlExporter]
67
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)]
78
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)]
89
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)]
910
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
1011
public class Benchmarks
1112
{
1213
private IIdGenerator<System.Snowflake, long> _idGenerator;
14+
private IIdGenerator<System.Snowflake, long> _idGeneratorBySecond;
15+
private IIdGenerator<System.Snowflake, long> _idGeneratorByEnableMachineClock;
16+
private IIdGenerator<System.Snowflake, long> _idGeneratorBySecondAndEnableMachineClock;
1317

1418
[GlobalSetup]
1519
public void GlobalSetup()
1620
{
17-
IServiceCollection services = new ServiceCollection();
18-
services.AddSnowflake();
19-
var serviceProvider = services.BuildServiceProvider();
20-
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
21-
_idGenerator.NewId();
21+
_idGenerator = InitializeIdGenerator(services => services.AddSnowflake());
22+
_idGeneratorBySecond =
23+
InitializeIdGenerator(services => services.AddSnowflake(options => options.TimestampType = TimestampType.Seconds));
24+
_idGeneratorByEnableMachineClock =
25+
InitializeIdGenerator(services => services.AddSnowflake(options => options.EnableMachineClock = true));
26+
_idGeneratorBySecondAndEnableMachineClock =
27+
InitializeIdGenerator(services => services.AddSnowflake(options =>
28+
{
29+
options.EnableMachineClock = true;
30+
options.TimestampType = TimestampType.Seconds;
31+
}));
2232
}
2333

24-
[Benchmark]
25-
public void SnowflakeByMillisecond()
26-
{
27-
_idGenerator.NewId();
28-
}
29-
}
30-
31-
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)]
32-
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)]
33-
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)]
34-
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
35-
public class SecondBenchmarks
36-
{
37-
private IIdGenerator<System.Snowflake, long> _idGenerator;
38-
39-
[GlobalSetup]
40-
public void GlobalSetup()
34+
private IIdGenerator<System.Snowflake, long> InitializeIdGenerator(Action<IServiceCollection> action)
4135
{
4236
IServiceCollection services = new ServiceCollection();
43-
services.AddSnowflake(options => options.TimestampType = TimestampType.Seconds);
37+
action.Invoke(services);
4438
var serviceProvider = services.BuildServiceProvider();
45-
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
46-
_idGenerator.NewId();
39+
var idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
40+
idGenerator.NewId();
41+
return idGenerator;
4742
}
4843

44+
[Benchmark(Baseline = true)]
45+
public void SnowflakeByMillisecond()
46+
=> _idGenerator.NewId();
47+
4948
[Benchmark]
5049
public void SnowflakeBySecond()
51-
{
52-
_idGenerator.NewId();
53-
}
50+
=> _idGeneratorBySecond.NewId();
51+
52+
[Benchmark]
53+
public void SnowflakeByMillisecondAndEnableMachineClock()
54+
=> _idGeneratorByEnableMachineClock.NewId();
55+
56+
[Benchmark]
57+
public void SnowflakeBySecondAndEnableMachineClock()
58+
=> _idGeneratorBySecondAndEnableMachineClock.NewId();
5459
}

test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/DistributedBenchmarks.cs

+32-29
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@
33

44
namespace Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests;
55

6+
/// <summary>
7+
/// Only supports the use of Redis environment
8+
/// </summary>
69
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 1000)]
710
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 10000)]
811
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100000)]
912
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
1013
public class DistributedBenchmarks
1114
{
12-
private IIdGenerator<System.Snowflake, long> _idGenerator;
15+
// private IIdGenerator<System.Snowflake, long> _idGenerator;
1316

14-
[GlobalSetup]
15-
public void GlobalSetup()
16-
{
17-
IServiceCollection services = new ServiceCollection();
18-
services.AddMasaRedisCache(opt =>
19-
{
20-
opt.Password = "";
21-
opt.DefaultDatabase = 2;
22-
opt.Servers = new List<RedisServerOptions>()
23-
{
24-
new("127.0.0.1", 6379)
25-
};
26-
});
27-
services.AddSnowflake(options =>
28-
{
29-
options.UseRedis();
30-
options.EnableMachineClock = true;
31-
});
32-
var serviceProvider = services.BuildServiceProvider();
33-
_idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
34-
_idGenerator.NewId();
35-
}
36-
37-
[Benchmark]
38-
public void Distributed()
39-
{
40-
_idGenerator.NewId();
41-
}
17+
// [GlobalSetup]
18+
// public void GlobalSetup()
19+
// {
20+
// IServiceCollection services = new ServiceCollection();
21+
// services.AddMasaRedisCache(opt =>
22+
// {
23+
// opt.Password = "";
24+
// opt.DefaultDatabase = 2;
25+
// opt.Servers = new List<RedisServerOptions>()
26+
// {
27+
// new("127.0.0.1", 6379)
28+
// };
29+
// });
30+
// services.AddSnowflake(options =>
31+
// {
32+
// options.UseRedis();
33+
// options.EnableMachineClock = true;
34+
// });
35+
// var serviceProvider = services.BuildServiceProvider();
36+
// _idGenerator = serviceProvider.GetRequiredService<IIdGenerator<System.Snowflake, long>>();
37+
// _idGenerator.NewId();
38+
// }
39+
//
40+
// [Benchmark]
41+
// public void Distributed()
42+
// {
43+
// _idGenerator.NewId();
44+
// }
4245
}

test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/MachineClockBenchmarks.cs

-29
This file was deleted.

test/Masa.Contrib.Data.IdGenerator.Snowflake.BenchmarkDotnet.Tests/Program.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ static void Main(string[] args)
1010
var config = DefaultConfig.Instance
1111
.AddValidator(ExecutionValidator.FailOnError)
1212
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
13-
// BenchmarkRunner.Run<Benchmarks>(config);
14-
// BenchmarkRunner.Run<SecondBenchmarks>(config);
15-
BenchmarkRunner.Run<MachineClockBenchmarks>(config);
13+
BenchmarkRunner.Run<Benchmarks>(config);
1614
// BenchmarkRunner.Run<DistributedBenchmarks>(config);
1715
Console.ReadLine();
1816
}

test/Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests/Benchmarks.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Masa.Contrib.Dispatcher.Events.BenchmarkDotnet.Tests;
55

6+
[MarkdownExporter, AsciiDocExporter, HtmlExporter]
67
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net60, targetCount: 100)]
78
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
89
public class Benchmarks
@@ -35,7 +36,7 @@ public void GlobalSetup()
3536
};
3637
}
3738

38-
[Benchmark]
39+
[Benchmark(Baseline = true)]
3940
public async Task SendCouponByDirect()
4041
{
4142
var _couponHandler = new CouponHandler(_serviceProvider);

0 commit comments

Comments
 (0)