You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.6 KiB
54 lines
1.6 KiB
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Options;
|
|
using Serilog;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace Win.Abp.Snowflakes.Test
|
|
{
|
|
public class SnowflakesTestService : ITransientDependency
|
|
{
|
|
private ISnowflakeIdGenerator _snowflakeIdGenerator;
|
|
private AbpSnowflakeIdGeneratorOptions _options;
|
|
|
|
public SnowflakesTestService(
|
|
ISnowflakeIdGenerator snowflakeIdGenerator,
|
|
IOptions<AbpSnowflakeIdGeneratorOptions> options
|
|
)
|
|
{
|
|
_snowflakeIdGenerator = snowflakeIdGenerator;
|
|
_options = options.Value;
|
|
}
|
|
|
|
public async Task RunAsync()
|
|
{
|
|
Log.Information("SnowflakeId Generator Test");
|
|
await TestSnowflakeIdGenerator();
|
|
}
|
|
|
|
private async Task TestSnowflakeIdGenerator()
|
|
{
|
|
var list = new List<long>();
|
|
var sw = new Stopwatch();
|
|
sw.Start();
|
|
int n = 1_000_000;
|
|
for (var i = 0; i < n; i++)
|
|
{
|
|
var id =await _snowflakeIdGenerator.CreateAsync();
|
|
list.Add(id);
|
|
if(i>n-100)
|
|
{
|
|
Log.Information(id.ToString());
|
|
}
|
|
// var info = $"{_options.DefaultDatacenterId} {_options.DefaultWorkerId} {DateTime.Now} {id}";
|
|
// Log.Information(info);
|
|
// await Task.Delay(100);
|
|
}
|
|
|
|
sw.Stop();
|
|
Log.Information(list.Count.ToString());
|
|
Log.Information(sw.ElapsedMilliseconds.ToString());
|
|
}
|
|
}
|
|
}
|