1
0
mirror of synced 2025-12-25 14:37:57 +08:00

增加测试demo

This commit is contained in:
zhupengfei
2021-10-26 13:05:02 +08:00
parent d8d8714eaf
commit 7b7c69a368
2 changed files with 25 additions and 1 deletions

View File

@@ -171,4 +171,10 @@ $ ts-node test/test4.ts
}
}
```
```
## 其他帮助
在mysql中int类型最大长度是10位数字由于本算法默认生成的是15位最短也是11位所以在mysql中需要使用bigint数据类型

18
TypeScript/test/test5.ts Normal file
View File

@@ -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)