Skip to content

A WebAssembly implementation of UUID v1 generator and parser

License

Notifications You must be signed in to change notification settings

mishimastar/uuid-wasm

Repository files navigation

uuid-wasm

Version Documentation Maintenance License: MIT

A WebAssembly implementation of UUID v1 generator and parser

Supports both ESM an CommonJS

About

The Fastest UUID v1 Parser and Generator for NodeJS.

The results were obtained by running each function inconsistently 1,000,000 times with NodeJS v20.8.1, R7 6800H, 16g DDR5

Parsing (string --> Data) Average, ops Median, ops
uuid-wasi@0.2.0 unsafe 4,414,844 ± 4.27 % 4,524,905 ± 5.26 %
uuid-wasi@0.2.0 safe 3,884,245 ± 2.24 % 3,984,022 ± 2.46 %
uuid@9.0.0 ----- -----
cassandra-driver@4.6.4 906,154 ± 5.43 % 924,215 ± 6.76 %

Generate (--> string) Average, ops Median, ops
uuid-wasi@0.2.0 6,516,927 ± 10.13 % 6,584,145 ± 12.64 %
uuid@9.0.0 3,705,620 ± 7.15 % 3,785,155 ± 9.99 %
cassandra-driver@4.6.4 278,435 ± 6.48 % 286,600 ± 9.92 %

Prerequisites

  • node >=14.21.3

Install

npm i uuid-wasm

Usage

import { InitUUID } from 'uuid-wasm';

const run = async () => {
    const { v1, nanos, timeFromV1, unsafeTimeFromV1 } = await InitUUID();

    const uuid = v1();
    console.log(uuid);
    // 6335ff92-6a7a-11ee-929a-eedc63b9d38e

    const nanoseconds = nanos();
    console.log(nanoseconds);
    // 1697278437810573000n

    const date1 = timeFromV1(uuid);
    console.log(date1);
    // 2023-10-14T10:13:57.810Z
    console.log(date1.getTime());
    // 1697278547627

    const date2 = unsafeTimeFromV1(uuid);
    console.log(date2);
    // 2023-10-14T10:13:57.810Z
    console.log(date2.getTime());
    // 1697278547627
};

run().catch(console.error);

Author

Sergey Saltykov

Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

License

Copyright © 2023 Sergey Saltykov.
This project is MIT licensed.

About

A WebAssembly implementation of UUID v1 generator and parser

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published