From 7b7c69a36841f15126b349eeda8454abf9b2d329 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Tue, 26 Oct 2021 13:05:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TypeScript/README.md | 8 +++++++- TypeScript/test/test5.ts | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 TypeScript/test/test5.ts diff --git a/TypeScript/README.md b/TypeScript/README.md index aa8c1cb..f0e47b5 100644 --- a/TypeScript/README.md +++ b/TypeScript/README.md @@ -171,4 +171,10 @@ $ ts-node test/test4.ts } } -``` \ No newline at end of file +``` + +## 其他帮助 + +在mysql中int类型最大长度是10位数字,由于本算法默认生成的是15位,最短也是11位,所以在mysql中需要使用bigint数据类型 + + diff --git a/TypeScript/test/test5.ts b/TypeScript/test/test5.ts new file mode 100644 index 0000000..5877aca --- /dev/null +++ b/TypeScript/test/test5.ts @@ -0,0 +1,18 @@ +import { snowflakeIdv1 } from '../snowflakeIdv1' + +const WorkerId = process.env.WorkerId == undefined ? 1 : process.env.WorkerId + +let gen1 = new snowflakeIdv1({ WorkerId: WorkerId, SeqBitLength: 10 }) +// for (let i = 0; i < 10; i++) { +// let id1 = gen1.NextId() +// console.log(`${i} ID:${id1} ${typeof id1} 长度:${id1.toString().length}`) +// } + +console.time("Test Run") +const HSet = new Set() +for (let index = 0; index < 500000; index++) { + HSet.add(gen1.NextId()) +} +console.timeEnd("Test Run") +console.log([...HSet.values()].join("\n")) +console.log(HSet.size) \ No newline at end of file -- GitLab