diff --git a/C#.NET/source/Yitter.IdGenTest/Program.cs b/C#.NET/source/Yitter.IdGenTest/Program.cs index 3968244..74228a2 100644 --- a/C#.NET/source/Yitter.IdGenTest/Program.cs +++ b/C#.NET/source/Yitter.IdGenTest/Program.cs @@ -12,7 +12,7 @@ namespace Yitter.OrgSystem.TestA class Program { // 测试参数(默认配置下,最佳性能是10W/s) - static int genIdCount = 2;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为20000或适当增加SeqBitLength) + static int genIdCount = 500000;//5000; // 计算ID数量(如果要验证50W效率,请将TopOverCostCount设置为2000或适当增加SeqBitLength) static short method = 1; // 1-漂移算法,2-传统算法 @@ -27,6 +27,9 @@ namespace Yitter.OrgSystem.TestA static void Main(string[] args) { + RunSingle(); + return; + Console.WriteLine("Hello World! C#"); var options = new IdGeneratorOptions() @@ -130,16 +133,42 @@ namespace Yitter.OrgSystem.TestA private static void RunSingle() { - DateTime start = DateTime.Now; - for (int i = 0; i < genIdCount; i++) + var options = new IdGeneratorOptions() { - var id = IdGen.NewLong(); - } + Method = 1, + WorkerId = 1, + + //WorkerIdBitLength = 6, + SeqBitLength = 6, + + //DataCenterIdBitLength = 0, + //TopOverCostCount = 2000, - DateTime end = DateTime.Now; - Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++, total: {(end - start).TotalMilliseconds} ms"); - Interlocked.Increment(ref Program.Count); + //TimestampType = 1, + // MinSeqNumber = 1, + // MaxSeqNumber = 200, + // BaseTime = DateTime.Now.AddYears(-10), + }; + + //IdGen = new DefaultIdGenerator(options); + YitIdHelper.SetIdGenerator(options); + + while (true) + { + DateTime start = DateTime.Now; + + for (int i = 0; i < genIdCount; i++) + { + //var id = IdGen.NewLong(); + var id = YitIdHelper.NextId(); + } + + DateTime end = DateTime.Now; + Console.WriteLine($"++++++++++++++++++++++++++++++++++++++++, total: {(end - start).TotalMilliseconds} ms"); + Thread.Sleep(1000); + } + //Interlocked.Increment(ref Program.Count); } private static void Go(IdGeneratorOptions options) diff --git a/C/source/main.c b/C/source/main.c index 6be35b5..9289b08 100644 --- a/C/source/main.c +++ b/C/source/main.c @@ -13,51 +13,62 @@ #include "idgen/IdGenerator.h" #include "YitIdHelper.h" - -const int GenIdCount = 50000; +const int GenIdCount = 500000; const bool multiThread = false; const int threadCount = 50; const int method = 1; -void RunMultiThread() { - //int64_t start = GetCurrentMicroTime(); - for (int i = 0; i < GenIdCount / threadCount; i++) { +void RunMultiThread() +{ + // int64_t start = GetCurrentMicroTime(); + for (int i = 0; i < GenIdCount / threadCount; i++) + { int64_t id = NextId(); printf("ID: %D\n", id); } int64_t end = GetCurrentMicroTime(); - //printf("%s,total:%d μs\n", method == 1 ? "1" : "2", (end - start)); + // printf("%s,total:%d μs\n", method == 1 ? "1" : "2", (end - start)); } -void RunSingle() { +void RunSingle() +{ int64_t start = GetCurrentMicroTime(); - for (int i = 0; i < GenIdCount; i++) { + for (int i = 0; i < GenIdCount; i++) + { int64_t id = NextId(); -// printf("ID: %ld\n", id); + // printf("ID: %ld\n", id); } int64_t end = GetCurrentMicroTime(); printf("%s, total: %d us\n", method == 1 ? "1" : "2", (end - start)); } -int main() { +int main() +{ IdGeneratorOptions options = BuildIdGenOptions(1); options.Method = method; options.WorkerId = 1; - options.SeqBitLength = 6; + options.SeqBitLength = 10; + // options.TopOverCostCount = 2000; SetIdGenerator(options); pthread_t tid[threadCount]; - while (1) { - if (multiThread) { - for (int i = 0; i < threadCount; i++) { - if (pthread_create(&tid[i], NULL, (void *) RunMultiThread, NULL) != 0) { + while (1) + { + if (multiThread) + { + for (int i = 0; i < threadCount; i++) + { + if (pthread_create(&tid[i], NULL, (void *)RunMultiThread, NULL) != 0) + { printf("thread creation failed\n"); exit(1); } } - } else { + } + else + { RunSingle(); } diff --git a/Go/source/main.go b/Go/source/main.go index 37781c5..d3ccfb3 100644 --- a/Go/source/main.go +++ b/Go/source/main.go @@ -24,22 +24,24 @@ func main() { // 自定义参数 var options = idgen.NewIdGeneratorOptions(1) options.WorkerIdBitLength = 6 - options.SeqBitLength = 6 + options.SeqBitLength = 10 options.BaseTime = time.Date(2020, 2, 20, 2, 20, 2, 20, time.UTC).UnixNano() / 1e6 idgen.SetIdGenerator(options) - var genCount = 50000 - for { - var begin = time.Now().UnixNano() / 1e3 - for i := 0; i < genCount; i++ { - // 生成ID - id := idgen.NextId() - fmt.Println(id) + var genCount = 500000 + for j := 0; j < 100000; j++ { + for { + var begin = time.Now().UnixNano() / 1e6 + for i := 0; i < genCount; i++ { + // 生成ID + idgen.NextId() + // fmt.Println(id) + } + var end = time.Now().UnixNano() / 1e6 + + fmt.Println("耗时:", (end - begin), "ms") + time.Sleep(time.Duration(1000) * time.Millisecond) } - var end = time.Now().UnixNano() / 1e3 - - fmt.Println(end - begin) - time.Sleep(time.Duration(1000) * time.Millisecond) } } else { // ip := "localhost" diff --git a/Java/source/.gitignore b/Java/source/.gitignore index b551e8b..e4b0fc4 100644 --- a/Java/source/.gitignore +++ b/Java/source/.gitignore @@ -19,7 +19,9 @@ *.zip *.tar.gz *.rar -target/ +target +.vscode +*.code-workspace # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/Java/source/pom.xml b/Java/source/pom.xml index 0d8f601..1b154b2 100644 --- a/Java/source/pom.xml +++ b/Java/source/pom.xml @@ -41,9 +41,9 @@ UTF-8 UTF-8 - 1.8 - 1.8 - 1.8 + 11 + 11 + 11 diff --git a/Java/source/src/test/java/com/github/yitter/test/StartUp.java b/Java/source/src/test/java/com/github/yitter/test/StartUp.java index a2334d4..7f57b59 100644 --- a/Java/source/src/test/java/com/github/yitter/test/StartUp.java +++ b/Java/source/src/test/java/com/github/yitter/test/StartUp.java @@ -12,7 +12,7 @@ public class StartUp { * [不同CPU可能结果有差异,但相对大小不变] * 默认配置下,最佳性能是5W/s-8W/s */ - final static int genIdCount = 50000; + final static int genIdCount = 500000; //1-漂移算法,2-传统算法 final static short method = 1; @@ -20,11 +20,12 @@ public class StartUp { public static void main(String[] args) { IdGeneratorOptions options = new IdGeneratorOptions(); -// options.WorkerIdBitLength = 6; -// options.SeqBitLength = 6; +// options.WorkerIdBitLength = 6; // 默认6 + options.SeqBitLength = 10; // 默认6 // options.BaseTime = 1582206693000L; options.Method = method; options.WorkerId = 1; + options.TopOverCostCount=2000; // 首先测试一下 IdHelper 方法,获取单个Id YitIdHelper.setIdGenerator(options);