public void DistinctLongIdsForMultiThreads() { Thread[] threads = new Thread[HowManyThreads]; long[][] ids = new long[HowManyThreads][]; List <long> allIds = new List <long>(HowManyIds * HowManyThreads); IIdGenerator <long> idGenerator = new Id64Generator(); for (int i = 0; i < HowManyThreads; i++) { var threadId = i; threads[i] = new Thread(() => { ids[threadId] = idGenerator.Take(HowManyIds).ToArray(); }); threads[i].Start(); } for (int i = 0; i < HowManyThreads; i++) { threads[i].Join(); Assert.IsTrue(AssertUtil.AreUnique(ids[i]), "All ids needs to be unique"); Assert.IsTrue(AssertUtil.AreSorted(ids[i]), "Ids array needs to be ordered"); allIds.AddRange(ids[i]); } Assert.AreEqual( HowManyIds * HowManyThreads, allIds.Distinct().Count(), "All ids needs to be unique"); }
public void DistinctLongIdsForMultiThreads() { Thread[] threads = new Thread[HowManyThreads]; long[][] ids = new long[HowManyThreads][]; List<long> allIds = new List<long>(HowManyIds * HowManyThreads); IIdGenerator<long> idGenerator = new Id64Generator(); for (int i = 0; i < HowManyThreads; i++) { var threadId = i; threads[i] = new Thread(() => { ids[threadId] = idGenerator.Take(HowManyIds).ToArray(); }); threads[i].Start(); } for (int i = 0; i < HowManyThreads; i++) { threads[i].Join(); Assert.True(AssertUtil.AreUnique(ids[i]), "All ids needs to be unique"); Assert.True(AssertUtil.AreSorted(ids[i]), "Ids array needs to be ordered"); allIds.AddRange(ids[i]); } Assert.Equal(HowManyIds * HowManyThreads, allIds.Distinct().Count()); }
public void UniqueLongIds() { IIdGenerator<long> idGenerator = new Id64Generator(); long[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.True(AssertUtil.AreUnique(ids), "All ids needs to be unique"); }
public void SortableLongIds() { IIdGenerator<long> idGenerator = new Id64Generator(); long[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.True(AssertUtil.AreSorted(ids), "Ids array needs to be ordered"); }
public void SortableLongIds() { IIdGenerator <long> idGenerator = new Id64Generator(); long[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.IsTrue(AssertUtil.AreSorted(ids), "Ids array needs to be ordered"); }
public void UniqueLongIds() { IIdGenerator <long> idGenerator = new Id64Generator(); long[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.IsTrue(AssertUtil.AreUnique(ids), "All ids needs to be unique"); }
public void Long64BitGeneratorTimeTest() { var id64Generator = new Id64Generator(); CodeTimer.Time("生成随机", 10, () => { id64Generator.Take(1000000).ToArray(); }); }
private static void Long64BitGenerator() { Console.WriteLine(" == Long ids (64 bit) =="); var id64Generator = new Id64Generator(); foreach (var id in id64Generator.Take(5).ToArray()) { GetBytesUInt64((ulong)id); } }
private static void Long64BitGenerator() { Debug.Log(" == Long ids (64 bit) =="); var id64Generator = new Id64Generator(); foreach (var id in id64Generator.Take(5).ToArray()) { GetBytesUInt64((ulong)id); } }
public void Long64BitGeneratorTest() { var id64Generator = new Id64Generator(); for (int i = 0; i < 20; i++) { _output.WriteLine(Long64BitGenerator().ToString()); Thread.Sleep(1); } }
public void TestOtherEpoch() { var date = new DateTime(1985, 1, 1); var id = new Id64Generator(ConvertDataTimeLong(date), 1, 1); _output.WriteLine(id.GenerateId().ToString()); var date1 = new DateTime(1986, 1, 1); var id1 = new Id64Generator(ConvertDataTimeLong(date1), 2, 1); _output.WriteLine(id1.GenerateId().ToString()); }
public static void SetMachineId(short machineId) { MachineId = machineId; // 마스크 Index 순서 바꾸지 말것!! _id64GeneratorAccountDBKey = new Id64Generator(machineId, 0, GenCustomMask(1)); _id64GeneratorEZBotDBKey = new Id64Generator(machineId, 0, GenCustomMask(2)); _id64GeneratorExchangeDBKey = new Id64Generator(machineId, 0, GenCustomMask(3)); _id64GeneratorTransactionDBKey = new Id64Generator(machineId, 0, GenCustomMask(4)); _idGeneratorVerifyCode = new IdStringGeneratorWrapper(new Id64Generator(machineId, 0, 0xb25e3f91), IdStringGeneratorWrapper.Base32, "V"); _idGeneratorActivationCode = new IdStringGeneratorWrapper(new Id64Generator(machineId, 0, 0xb25e3f91), IdStringGeneratorWrapper.Base32, "A"); _idGeneratorAccessToken = new IdStringGeneratorWrapper(new Id64Generator(machineId, 0, 0xb25e3f91), IdStringGeneratorWrapper.Base32, "AT"); }
// Start is called before the first frame update private void Start() { Debug.Log(Id); const int count = 1; var unique = new Id64Generator(10); var unique2 = new IdGuidGenerator(10); var unique3 = new IdStringGeneratorWrapper(unique); Profiler.BeginSample("track snowflake 1"); string str1 = ""; for (int i = 0; i < count; i++) { str1 = unique.GenerateId().ToString(); } Profiler.EndSample(); Profiler.BeginSample("track snowflake 2"); for (int i = 0; i < count; i++) { unique2.GenerateId(); } Profiler.EndSample(); Profiler.BeginSample("track snowflake 3"); string str2 = ""; for (int i = 0; i < count; i++) { str2 = unique3.GenerateId(); } Profiler.EndSample(); Profiler.BeginSample("track guid"); for (int i = 0; i < count; i++) { Guid.NewGuid(); } Profiler.EndSample(); Debug.Log(str1); Debug.Log(str2); Main(); }
public static bool SetMachineId(short machineId) { if (IsValidMachineId(machineId) == false) { return(false); } MachineId = machineId; // 마스크 Index 순서 바꾸지 말것!! _id64Gen_UserId = new Id64Generator(machineId, 0, GenCustomMask(1)); _id64Gen_AppId = new Id64Generator(machineId, 0, GenCustomMask(2)); _id64Gen_AdUnitId = new Id64Generator(machineId, 0, GenCustomMask(3)); _id64Gen_CampaignId = new Id64Generator(machineId, 0, GenCustomMask(4)); _id64Gen_AdDesignId = new Id64Generator(machineId, 0, GenCustomMask(5)); _id64Gen_AdResourceId = new Id64Generator(machineId, 0, GenCustomMask(6)); _id64Gen_AdHistoryId = new Id64Generator(machineId, 0, GenCustomMask(7)); _id64Gen_MiningHistoryId = new Id64Generator(machineId, 0, GenCustomMask(8)); _idGen_VerifyCode = new IdStringGeneratorWrapper(new Id64Generator(machineId, 0, GenCustomMask(5)), IdStringGeneratorWrapper.Base32, "V"); return(true); }
static SequenceQueue() { id64Generator = new Id64Generator(); idGuid = new IdGuidGenerator(); }
public long Long64BitGenerator() { var id64Generator = new Id64Generator();// _container.Resolve<Id64Generator>(); return(id64Generator.GenerateId()); }