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 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(); 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()); } } }