dylang / shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
https://www.npmjs.org/package/shortid
Other
5.74k stars 258 forks source link

Move to NanoID #121

Closed shashkovdanil closed 6 years ago

shashkovdanil commented 6 years ago

Integrated nanoid for generating id

ai commented 6 years ago

@shashkovdanil can you test distribution and use NanoID performance benchmark to prove that we improve shortid?

shashkovdanil commented 6 years ago

@ai, OK.

shashkovdanil commented 6 years ago

@ai, shortid was improved 🚀

has flat distribution test:

has flat distribution shortid with nanoid

    expect(received).toBeCloseTo(expected, precision)

    Precision: 1-digit
    Expected: 1
    Received: 1.3898666666666666


has flat distribution shortid original

    expect(received).toBeCloseTo(expected, precision)

    Precision: 1-digit
    Expected: 1
    Received: 2.3356444444444446

Benchmark test:

nanoid          149,530 ops/sec 
nanoid/generate 154,555 ops/sec 
uuid/v4         148,375 ops/sec 
shortid          12,988 ops/sec 
nanoid          149,435 ops/sec 
nanoid/generate 148,073 ops/sec 
uuid/v4         152,058 ops/sec 
shortid          14,737 ops/sec 
ai commented 6 years ago

@shashkovdanil in this test every symbol had different distribution, so you can't just show one number.

Post chars[k] content instead.

Also performance reducing if not do great.

ai commented 6 years ago

I improved performance:

shortid old        33,979 ops/sec 
shortid new        82,404 ops/sec