private static void MacAddressGenerator() { var mac = NetworkInterface.GetAllNetworkInterfaces().First(i => i.OperationalStatus == OperationalStatus.Up).GetPhysicalAddress().GetAddressBytes(); if (BitConverter.IsLittleEndian) { Array.Reverse(mac); } var generator = new IdGuidGenerator(mac); Debug.Log($" == Guid ids with MAC Address identifier ({BitConverter.ToString(mac)}) =="); foreach (var id in generator.Take(5).ToArray()) { Debug.Log(id); } Debug.Log($" == Guid ids with MAC Address identifier:[{BitConverter.ToString(mac)}] and epoch:[{new DateTime(2012, 10, 1)}] == "); generator = new IdGuidGenerator(mac, new DateTime(2012, 10, 1)); foreach (var id in generator.Take(5).ToArray()) { Debug.Log(id); } }
public void DistinctGuidIdsForMultiThreads() { Thread[] threads = new Thread[HowManyThreads]; Guid[][] ids = new Guid[HowManyThreads][]; List <Guid> allIds = new List <Guid>(HowManyIds * HowManyThreads); IIdGenerator <Guid> idGenerator = new IdGuidGenerator(); 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 static void MacAddressGenerator() { var mac = NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.OperationalStatus == OperationalStatus.Up) .First().GetPhysicalAddress().GetAddressBytes(); if (BitConverter.IsLittleEndian) Array.Reverse(mac); var generator = new IdGuidGenerator(mac); Console.WriteLine(); Console.WriteLine(" == Guid ids with MAC Address identifier ({0}) ==", BitConverter.ToString(mac)); foreach (var id in generator.Take(5).ToArray()) { Console.WriteLine(id); } Console.WriteLine(); Console.WriteLine(" == Guid ids with MAC Address identifier:[{0}] and epoch:[{1}] ==", BitConverter.ToString(mac), new DateTime(2012, 10, 1)); generator = new IdGuidGenerator(mac, new DateTime(2012, 10, 1)); foreach (var id in generator.Take(5).ToArray()) { Console.WriteLine(id); } }
public static void MacAddressGenerator() { var mac = NetworkInterface.GetAllNetworkInterfaces() .Where(i => i.OperationalStatus == OperationalStatus.Up) .First().GetPhysicalAddress().GetAddressBytes(); if (BitConverter.IsLittleEndian) { Array.Reverse(mac); } var generator = new IdGuidGenerator(mac); Console.WriteLine(); Console.WriteLine(" == Guid ids with MAC Address identifier ({0}) ==", BitConverter.ToString(mac)); foreach (var id in generator.Take(5).ToArray()) { Console.WriteLine(id); } Console.WriteLine(); Console.WriteLine(" == Guid ids with MAC Address identifier:[{0}] and epoch:[{1}] ==", BitConverter.ToString(mac), new DateTime(2012, 10, 1)); generator = new IdGuidGenerator(mac, new DateTime(2012, 10, 1)); foreach (var id in generator.Take(5).ToArray()) { Console.WriteLine(id); } }
public void DistinctGuidIdsForMultiThreads() { Thread[] threads = new Thread[HowManyThreads]; Guid[][] ids = new Guid[HowManyThreads][]; List<Guid> allIds = new List<Guid>(HowManyIds * HowManyThreads); IIdGenerator<Guid> idGenerator = new IdGuidGenerator(); 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 SortableGuidIds() { IIdGenerator <Guid> idGenerator = new IdGuidGenerator(); Guid[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.IsTrue(AssertUtil.AreSorted(ids), "Ids array needs to be ordered"); }
public void SortableGuidIds() { IIdGenerator<Guid> idGenerator = new IdGuidGenerator(); Guid[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.IsTrue(AssertUtil.AreSorted(ids), "Ids array needs to be ordered"); }
public void UniqueGuidIds() { IIdGenerator<Guid> idGenerator = new IdGuidGenerator(); Guid[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.IsTrue(AssertUtil.AreUnique(ids), "All ids needs to be unique"); }
public void UniqueGuidIds() { IIdGenerator <Guid> idGenerator = new IdGuidGenerator(); Guid[] ids = idGenerator.Take(HowManyIds).ToArray(); Assert.IsTrue(AssertUtil.AreUnique(ids), "All ids needs to be unique"); }
private static void GuidGenerator() { Debug.Log(" == Guid ids =="); var idGuidGenerator = new IdGuidGenerator(0x123456789ABCL); foreach (var id in idGuidGenerator.Take(5).ToArray()) { Debug.Log(id); } }
private static void GuidGenerator() { Console.WriteLine(); Console.WriteLine(" == Guid ids =="); var idGuidGenerator = new IdGuidGenerator(0x123456789ABCL); foreach (var id in idGuidGenerator.Take(5).ToArray()) { Console.WriteLine(id); } }
private static void BenchmarkGuidGenerator() { int iterations = 128 * 1024 * 1024; Console.WriteLine(); Console.WriteLine(" == Benchmark Guid ids with {0} iterations ==", iterations); for (int i = 0; i < 5; i++) { var idGuidGenerator = new IdGuidGenerator(0x123456789ABCL); TimeSpan elapsed = Benchmark(idGuidGenerator, iterations); Console.WriteLine("Elapsed {0} ({1:0.#} id/sec)", elapsed, iterations / elapsed.TotalSeconds); } }
// 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 void IdentiferUsesLowOrderBytesOfInt64() { long identifier = 0x0123456789abcdef; IIdGenerator<Guid> idGenerator = new IdGuidGenerator(identifier); Guid id = idGenerator.GenerateId(); byte[] bytes = id.ToByteArray(); Assert.AreEqual((byte)0x45, bytes[8 + 0]); Assert.AreEqual((byte)0x67, bytes[8 + 1]); Assert.AreEqual((byte)0x89, bytes[8 + 2]); Assert.AreEqual((byte)0xab, bytes[8 + 3]); Assert.AreEqual((byte)0xcd, bytes[8 + 4]); Assert.AreEqual((byte)0xef, bytes[8 + 5]); }
public void IdentiferUsesLowOrderBytesOfInt64() { long identifier = 0x0123456789abcdef; IIdGenerator <Guid> idGenerator = new IdGuidGenerator(identifier); Guid id = idGenerator.GenerateId(); byte[] bytes = id.ToByteArray(); Assert.AreEqual((byte)0x45, bytes[8 + 0]); Assert.AreEqual((byte)0x67, bytes[8 + 1]); Assert.AreEqual((byte)0x89, bytes[8 + 2]); Assert.AreEqual((byte)0xab, bytes[8 + 3]); Assert.AreEqual((byte)0xcd, bytes[8 + 4]); Assert.AreEqual((byte)0xef, bytes[8 + 5]); }
static SequenceQueue() { id64Generator = new Id64Generator(); idGuid = new IdGuidGenerator(); }