/js-unit-conversion-benchmarks

Some benchmarks of community-made JavaScript libraries for converting units.

Primary LanguageTypeScript

JavaScript unit conversion benchmarks

Some benchmarks of community-made JavaScript/TypeScript libraries for converting units.

Results

Generated automatically at Thu, 17 Oct 2024 04:01:04 GMT with Node.js v20.17.0 (V8 v11.3.244.8-node.23) on fv-az1118-594 (Linux-x64 AMD EPYC 7763 64-Core Processor)

Each test was called 10,000 times to allow the runtime to warmup. Afterward 100,000 trials were performed for each library. Information about the execution times are shown below. Lower execution times and higher executions per second are better.

A baseline of raw math is included when relevant.

If you want a different library to be added to the benchmark, make an issue or create a pull request if you're comfortable.

Convert 24 hours to minutes

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 50ns (100%) 50ns (100%) 20,000,000/sec
convert (fast) 120ns (240%) 121ns (242%) 8,333,333/sec
simple-units (fast) 160ns (320%) 170ns (340%) 6,250,000/sec
uom (fast) 211ns (422%) 221ns (442%) 4,739,336/sec
moment (popular) 461ns (922%) 471ns (942%) 2,169,197/sec
safe-units (fast) 501ns (1,002%) 521ns (1,042%) 1,996,008/sec
dayjs (popular) 621ns (1,242%) 632ns (1,264%) 1,610,306/sec
luxon (popular) 1,132ns (2,264%) 1,172ns (2,344%) 883,392/sec
js-quantities (popular) 2,175ns (4,350%) 2,215ns (4,430%) 459,770/sec
convert-units (popular) 41,727ns (83,454%) 42,015ns (84,030%) 23,965/sec

Convert 8192 bytes to the best applicable unit

Library Median execution time 75th percentile execution time Executions per second
convert (fast) 741ns (100%) 801ns (108%) 1,349,528/sec
byte-size (popular) 28,687ns (3,871%) 29,615ns (3,997%) 34,859/sec
convert-units (popular) 90,303ns (12,187%) 90,815ns (12,256%) 11,074/sec

Convert 4 inches to millimeters

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 70ns (100%) 70ns (100%) 14,285,714/sec
convert (fast) 120ns (171%) 121ns (173%) 8,333,333/sec
simple-units (fast) 170ns (243%) 171ns (244%) 5,882,353/sec
uom (fast) 230ns (329%) 231ns (330%) 4,347,826/sec
safe-units (fast) 490ns (700%) 491ns (701%) 2,040,816/sec
js-quantities (popular) 2,175ns (3,107%) 2,195ns (3,136%) 459,770/sec
convert-units (popular) 21,263ns (30,376%) 21,343ns (30,490%) 47,030/sec

Convert 2.5 liters to cubic inches

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 50ns (100%) 50ns (100%) 20,000,000/sec
convert (fast) 121ns (242%) 140ns (280%) 8,264,463/sec
simple-units (fast) 141ns (282%) 150ns (300%) 7,092,199/sec
uom (fast) 501ns (1,002%) 521ns (1,042%) 1,996,008/sec
safe-units (fast) 1,193ns (2,386%) 1,212ns (2,424%) 838,223/sec
js-quantities (popular) 3,077ns (6,154%) 3,107ns (6,214%) 324,992/sec
convert-units (popular) 45,535ns (91,070%) 45,759ns (91,518%) 21,961/sec

Parse "10h" and convert it to milliseconds

Library Median execution time 75th percentile execution time Executions per second
ms (popular) 190ns (100%) 191ns (101%) 5,263,158/sec
@lukeed/ms (fast) 240ns (126%) 241ns (127%) 4,166,667/sec
convert (fast) 271ns (143%) 281ns (148%) 3,690,037/sec

Convert 24 hours to minutes, but with bigints

Library Median execution time 75th percentile execution time Executions per second
math (baseline) 50ns (100%) 61ns (122%) 20,000,000/sec
convert (fast) 100ns (200%) 150ns (300%) 10,000,000/sec