0.1.1 • Published 4 years ago
fast-id v0.1.1
Fast-Id
Quickly generate tens of millions of IDs (maximum 75200000), either sequentially or randomly.
Installation
npm install fast-id --save
Usage
Sequentially
Sequentially generate ids from 1 to 100:
const ID = require('fast-id')(100);
const main = () => {
let id;
// Fetch the next id
id = ID(); // 1
console.log(id);
// Fetch the next id
id = ID(); // 2
console.log(id);
};
main();
Randomly
Randomly generate ids from 1 to 100:
const ID = require('fast-id')(100, {isRandom: true});
const main = () => {
let id;
// Fetch the next id
id = ID(); // a random id between 1 and 100
console.log(id);
// Fetch the next id
id = ID(); // a random id between 1 and 100
console.log(id);
};
main();
Performance
1. Sequentially
Sequentially generating 10000000 ids takes less than 1 second.
const max = 10000000;
require('fast-id')(max, {logging: true});
The result will be like below:
fast-id initialized. [max = 10000000, 0.738s]
2. Randomly
Randomly generating 10000000 ids takes less than 1.5 seconds.
const max = 10000000;
require('fast-id')(max, {isRandom: true, logging: true});
The result will be like below:
fast-id initialized. [max = 10000000, 1.321s]
License
Copyright (c) 2019, Owen Luke